[PATCH] MAINTAINERS: add btrfs file entries

2017-03-02 Thread Dmitry V. Levin
Add file entries for btrfs header files.

Signed-off-by: Dmitry V. Levin 
Acked-by: David Sterba 
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0001835..04a758f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2904,6 +2904,8 @@ T:git 
git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git
 S: Maintained
 F: Documentation/filesystems/btrfs.txt
 F: fs/btrfs/
+F: include/linux/btrfs*
+F: include/uapi/linux/btrfs*
 
 BTTV VIDEO4LINUX DRIVER
 M: Mauro Carvalho Chehab 
-- 
ldv


[PATCH] uapi: fix linux/if_pppol2tp.h userspace compilation errors

2017-02-14 Thread Dmitry V. Levin
Move inclusion of  before 
to fix userspace compilation errors like this:

In file included from /usr/include/linux/l2tp.h:12:0,
 from /usr/include/linux/if_pppol2tp.h:21,
/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

Fixes: 47c3e7783be4 ("net: l2tp: deprecate PPPOL2TP_MSG_* in favour of 
L2TP_MSG_*")
Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/if_pppol2tp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/if_pppol2tp.h b/include/uapi/linux/if_pppol2tp.h
index 6418c4d..54a404e 100644
--- a/include/uapi/linux/if_pppol2tp.h
+++ b/include/uapi/linux/if_pppol2tp.h
@@ -16,9 +16,9 @@
 #define _UAPI__LINUX_IF_PPPOL2TP_H
 
 #include 
+#include 
 #include 
 #include 
-#include 
 
 /* Structure used to connect() the socket to a particular tunnel UDP
  * socket over IPv4.
-- 
ldv


Re: [PATCH] uapi: fix linux/if_pppol2tp.h userspace compilation errors

2017-02-14 Thread Dmitry V. Levin
On Tue, Feb 14, 2017 at 02:37:23PM -0500, David Miller wrote:
> From: "Dmitry V. Levin" 
> Date: Tue, 14 Feb 2017 13:33:53 +0300
> 
> > In file included from /usr/include/linux/l2tp.h:12:0,
> >  from /usr/include/linux/if_pppol2tp.h:21,
> > /usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'
> 
> This is protected properly by __UAPI_DEF_IN_ADDR, so whichever gets
> included first makes the definition.
> 
> This whole thing is designed so that if GLIBC headers are included
> first, __UAPI_DEF_IN_ADDR will be defined to zero, therefore
> linux/in.h won't try to make the definition.  Otherwise it will.
> 
> The facility should not be so fragile that we have to play all
> kinds of header ordering games.  We would be imposing the same
> strange rules on userspace applications including these headers
> which is completely unacceptable.

The facility is so fragile that netinet/in.h cannot be included after
linux/in.h:

$ gcc -S -o/dev/null -xc /dev/null -include /usr/include/linux/in.h -include 
/usr/include/netinet/in.h
In file included from :32:0:
/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'
 struct in_addr
^~~
In file included from :32:0:
/usr/include/linux/in.h:84:8: note: originally defined here
 struct in_addr {
^~~

> So if the facility isn't working correctly, let's fix that instead
> of fidgeting with include ordering all over the tree.

I don't mind if the whole facility will get fixed someday.
My humble objective was just to fix the regression introduced in v4.10-rc1
by commit 47c3e7783be4.


-- 
ldv


[PATCH v2] uapi: fix linux/if_pppol2tp.h userspace compilation errors

2017-02-14 Thread Dmitry V. Levin
Because of  interface limitations, 
provided by libc cannot be included after , therefore any
header that includes  cannot be included after .

Change uapi/linux/l2tp.h, the last uapi header that includes
, to include  and  instead of
 and use __SOCK_SIZE__ instead of sizeof(struct sockaddr)
the same way as uapi/linux/in.h does, to fix linux/if_pppol2tp.h userspace
compilation errors like this:

In file included from /usr/include/linux/l2tp.h:12:0,
 from /usr/include/linux/if_pppol2tp.h:21,
/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

Fixes: 47c3e7783be4 ("net: l2tp: deprecate PPPOL2TP_MSG_* in favour of 
L2TP_MSG_*")
Signed-off-by: Dmitry V. Levin 
---
v2: change uapi/linux/l2tp.h to fix 

 include/uapi/linux/l2tp.h | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/l2tp.h b/include/uapi/linux/l2tp.h
index 85ddb74..b23c191 100644
--- a/include/uapi/linux/l2tp.h
+++ b/include/uapi/linux/l2tp.h
@@ -9,9 +9,8 @@
 
 #include 
 #include 
-#ifndef __KERNEL__
-#include 
-#endif
+#include 
+#include 
 
 #define IPPROTO_L2TP   115
 
@@ -31,7 +30,7 @@ struct sockaddr_l2tpip {
__u32   l2tp_conn_id;   /* Connection ID of tunnel */
 
/* Pad to size of `struct sockaddr'. */
-   unsigned char   __pad[sizeof(struct sockaddr) -
+   unsigned char   __pad[__SOCK_SIZE__ -
  sizeof(__kernel_sa_family_t) -
  sizeof(__be16) - sizeof(struct in_addr) -
  sizeof(__u32)];
-- 
ldv


[PATCH] uapi: fix linux/btrfs.h userspace compilation error

2017-02-15 Thread Dmitry V. Levin
Stop using NULL to fix the following linux/btrfs.h userspace compilation
error:

/usr/include/linux/btrfs.h: In function 'btrfs_err_str':
/usr/include/linux/btrfs.h:740:11: error: 'NULL' undeclared (first use in this 
function)
return NULL;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/btrfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index db4c253..01c612f 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -737,7 +737,7 @@ static inline char *btrfs_err_str(enum btrfs_err_code 
err_code)
return "add/delete/balance/replace/resize operation "\
"in progress";
default:
-   return NULL;
+   return 0;
}
 }
 
-- 
ldv


[PATCH] uapi: fix linux/mqueue.h userspace compilation errors

2017-02-15 Thread Dmitry V. Levin
Include  to fix the following linux/mqueue.h userspace
compilation errors:

/usr/include/linux/mqueue.h:26:2: error: unknown type name '__kernel_long_t'
  __kernel_long_t mq_flags; /* message queue flags   */
/usr/include/linux/mqueue.h:27:2: error: unknown type name '__kernel_long_t'
  __kernel_long_t mq_maxmsg; /* maximum number of messages  */
/usr/include/linux/mqueue.h:28:2: error: unknown type name '__kernel_long_t'
  __kernel_long_t mq_msgsize; /* maximum message size   */
/usr/include/linux/mqueue.h:29:2: error: unknown type name '__kernel_long_t'
  __kernel_long_t mq_curmsgs; /* number of messages currently queued */
/usr/include/linux/mqueue.h:30:2: error: unknown type name '__kernel_long_t'
  __kernel_long_t __reserved[4]; /* ignored for input, zeroed for output */

This reverts commit 139a7bdc2b93 ("mqueue.h: don't include linux/types.h").

Fixes: 63159f5dcccb ("uapi: Use __kernel_long_t in struct mq_attr")
Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/mqueue.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/uapi/linux/mqueue.h b/include/uapi/linux/mqueue.h
index d0a2b8e..4170778 100644
--- a/include/uapi/linux/mqueue.h
+++ b/include/uapi/linux/mqueue.h
@@ -18,6 +18,8 @@
 #ifndef _LINUX_MQUEUE_H
 #define _LINUX_MQUEUE_H
 
+#include/* For __kernel_long_t. */
+
 #define MQ_PRIO_MAX32768
 /* per-uid limit of kernel memory used by mqueue, in bytes */
 #define MQ_BYTES_MAX   819200
-- 
ldv


[PATCH] uapi: fix linux/dlm_netlink.h userspace compilation error

2017-02-15 Thread Dmitry V. Levin
Include  to fix the following linux/dlm_netlink.h
userspace compilation error:

/usr/include/linux/dlm_netlink.h:35:21: error: 'DLM_RESNAME_MAXLEN' undeclared 
here (not in a function)
  char resource_name[DLM_RESNAME_MAXLEN];

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/dlm_netlink.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/dlm_netlink.h b/include/uapi/linux/dlm_netlink.h
index 647c8ef..ad60964 100644
--- a/include/uapi/linux/dlm_netlink.h
+++ b/include/uapi/linux/dlm_netlink.h
@@ -10,6 +10,7 @@
 #define _DLM_NETLINK_H
 
 #include 
+#include /* For DLM_RESNAME_MAXLEN. */
 
 enum {
DLM_STATUS_WAITING = 1,
-- 
ldv


[PATCH] uapi: fix linux/target_core_user.h userspace compilation errors

2017-02-15 Thread Dmitry V. Levin
Consistently use types from linux/types.h to fix the following
linux/target_core_user.h userspace compilation errors:

/usr/include/linux/target_core_user.h:108:4: error: unknown type name 'uint32_t'
uint32_t iov_cnt;
/usr/include/linux/target_core_user.h:109:4: error: unknown type name 'uint32_t'
uint32_t iov_bidi_cnt;
/usr/include/linux/target_core_user.h:110:4: error: unknown type name 'uint32_t'
uint32_t iov_dif_cnt;
/usr/include/linux/target_core_user.h:111:4: error: unknown type name 'uint64_t'
uint64_t cdb_off;
/usr/include/linux/target_core_user.h:112:4: error: unknown type name 'uint64_t'
uint64_t __pad1;
/usr/include/linux/target_core_user.h:113:4: error: unknown type name 'uint64_t'
uint64_t __pad2;
/usr/include/linux/target_core_user.h:117:4: error: unknown type name 'uint8_t'
uint8_t scsi_status;
/usr/include/linux/target_core_user.h:118:4: error: unknown type name 'uint8_t'
uint8_t __pad1;
/usr/include/linux/target_core_user.h:119:4: error: unknown type name 'uint16_t'
uint16_t __pad2;
/usr/include/linux/target_core_user.h:120:4: error: unknown type name 'uint32_t'
uint32_t __pad3;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/target_core_user.h | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/include/uapi/linux/target_core_user.h 
b/include/uapi/linux/target_core_user.h
index c506cdd..af17b41 100644
--- a/include/uapi/linux/target_core_user.h
+++ b/include/uapi/linux/target_core_user.h
@@ -105,26 +105,26 @@ struct tcmu_cmd_entry {
 
union {
struct {
-   uint32_t iov_cnt;
-   uint32_t iov_bidi_cnt;
-   uint32_t iov_dif_cnt;
-   uint64_t cdb_off;
-   uint64_t __pad1;
-   uint64_t __pad2;
+   __u32 iov_cnt;
+   __u32 iov_bidi_cnt;
+   __u32 iov_dif_cnt;
+   __u64 cdb_off;
+   __u64 __pad1;
+   __u64 __pad2;
struct iovec iov[0];
} req;
struct {
-   uint8_t scsi_status;
-   uint8_t __pad1;
-   uint16_t __pad2;
-   uint32_t __pad3;
+   __u8 scsi_status;
+   __u8 __pad1;
+   __u16 __pad2;
+   __u32 __pad3;
char sense_buffer[TCMU_SENSE_BUFFERSIZE];
} rsp;
};
 
 } __packed;
 
-#define TCMU_OP_ALIGN_SIZE sizeof(uint64_t)
+#define TCMU_OP_ALIGN_SIZE sizeof(__u64)
 
 enum tcmu_genl_cmd {
TCMU_CMD_UNSPEC,
-- 
ldv


[PATCH] uapi: fix linux/ipv6_route.h userspace compilation errors

2017-02-15 Thread Dmitry V. Levin
Include  to fix the following linux/ipv6_route.h userspace
compilation errors:

/usr/include/linux/ipv6_route.h:42:19: error: field 'rtmsg_dst' has incomplete 
type
  struct in6_addr  rtmsg_dst;
/usr/include/linux/ipv6_route.h:43:19: error: field 'rtmsg_src' has incomplete 
type
  struct in6_addr  rtmsg_src;
/ust/include/linux/ipv6_route.h:44:19: error: field 'rtmsg_gateway' has 
incomplete type
  struct in6_addr  rtmsg_gateway;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/ipv6_route.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/ipv6_route.h b/include/uapi/linux/ipv6_route.h
index f6598d1..85bbb17 100644
--- a/include/uapi/linux/ipv6_route.h
+++ b/include/uapi/linux/ipv6_route.h
@@ -14,6 +14,7 @@
 #define _UAPI_LINUX_IPV6_ROUTE_H
 
 #include 
+#include  /* For struct in6_addr. */
 
 #define RTF_DEFAULT0x0001  /* default - learned via ND */
 #define RTF_ALLONLINK  0x0002  /* (deprecated and will be removed)
-- 
ldv


[PATCH] uapi: fix linux/mroute6.h userspace compilation errors

2017-02-15 Thread Dmitry V. Levin
Include  to fix the following linux/mroute6.h userspace
compilation errors:

/usr/include/linux/mroute6.h:80:22: error: field 'mf6cc_origin' has incomplete 
type
  struct sockaddr_in6 mf6cc_origin;  /* Origin of mcast */
/usr/include/linux/mroute6.h:81:22: error: field 'mf6cc_mcastgrp' has 
incomplete type
  struct sockaddr_in6 mf6cc_mcastgrp;  /* Group in question */
/usr/include/linux/mroute6.h:91:22: error: field 'src' has incomplete type
  struct sockaddr_in6 src;
/usr/include/linux/mroute6.h:92:22: error: field 'grp' has incomplete type
  struct sockaddr_in6 grp;
/usr/include/linux/mroute6.h:132:18: error: field 'im6_src' has incomplete type
  struct in6_addr im6_src, im6_dst;
/usr/include/linux/mroute6.h:132:27: error: field 'im6_dst' has incomplete type
  struct in6_addr im6_src, im6_dst;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/mroute6.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/mroute6.h b/include/uapi/linux/mroute6.h
index 5062fb5..ed57211 100644
--- a/include/uapi/linux/mroute6.h
+++ b/include/uapi/linux/mroute6.h
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include  /* For struct sockaddr_in6. */
 
 /*
  * Based on the MROUTING 3.5 defines primarily to keep
-- 
ldv


[PATCH] uapi: fix linux/mroute.h userspace compilation errors

2017-02-15 Thread Dmitry V. Levin
Include  to fix the following linux/mroute.h userspace
compilation errors:

/usr/include/linux/mroute.h:58:18: error: field 'vifc_lcl_addr' has incomplete 
type
  struct in_addr vifc_lcl_addr; /* Local interface address */
/usr/include/linux/mroute.h:61:17: error: field 'vifc_rmt_addr' has incomplete 
type
  struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
/usr/include/linux/mroute.h:72:17: error: field 'mfcc_origin' has incomplete 
type
  struct in_addr mfcc_origin;  /* Origin of mcast */
/usr/include/linux/mroute.h:73:17: error: field 'mfcc_mcastgrp' has incomplete 
type
  struct in_addr mfcc_mcastgrp;  /* Group in question */
/usr/include/linux/mroute.h:84:17: error: field 'src' has incomplete type
  struct in_addr src;
/usr/include/linux/mroute.h:85:17: error: field 'grp' has incomplete type
  struct in_addr grp;
/usr/include/linux/mroute.h:109:17: error: field 'im_src' has incomplete type
  struct in_addr im_src,im_dst;
/usr/include/linux/mroute.h:109:24: error: field 'im_dst' has incomplete type
  struct in_addr im_src,im_dst;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/mroute.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/mroute.h b/include/uapi/linux/mroute.h
index cf94301..1fe4c1e 100644
--- a/include/uapi/linux/mroute.h
+++ b/include/uapi/linux/mroute.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include   /* For struct in_addr. */
 
 /* Based on the MROUTING 3.5 defines primarily to keep
  * source compatibility with BSD.
-- 
ldv


[PATCH 1/2] uapi: fix linux/rds.h userspace compilation errors

2017-02-15 Thread Dmitry V. Levin
Consistently use types from linux/types.h to fix the following
linux/rds.h userspace compilation errors:

/usr/include/linux/rds.h:106:2: error: unknown type name 'uint8_t'
  uint8_t name[32];
/usr/include/linux/rds.h:107:2: error: unknown type name 'uint64_t'
  uint64_t value;
/usr/include/linux/rds.h:117:2: error: unknown type name 'uint64_t'
  uint64_t next_tx_seq;
/usr/include/linux/rds.h:118:2: error: unknown type name 'uint64_t'
  uint64_t next_rx_seq;
/usr/include/linux/rds.h:121:2: error: unknown type name 'uint8_t'
  uint8_t transport[TRANSNAMSIZ];  /* null term ascii */
/usr/include/linux/rds.h:122:2: error: unknown type name 'uint8_t'
  uint8_t flags;
/usr/include/linux/rds.h:129:2: error: unknown type name 'uint64_t'
  uint64_t seq;
/usr/include/linux/rds.h:130:2: error: unknown type name 'uint32_t'
  uint32_t len;
/usr/include/linux/rds.h:135:2: error: unknown type name 'uint8_t'
  uint8_t flags;
/usr/include/linux/rds.h:139:2: error: unknown type name 'uint32_t'
  uint32_t sndbuf;
/usr/include/linux/rds.h:144:2: error: unknown type name 'uint32_t'
  uint32_t rcvbuf;
/usr/include/linux/rds.h:145:2: error: unknown type name 'uint64_t'
  uint64_t inum;
/usr/include/linux/rds.h:153:2: error: unknown type name 'uint64_t'
  uint64_t   hdr_rem;
/usr/include/linux/rds.h:154:2: error: unknown type name 'uint64_t'
  uint64_t   data_rem;
/usr/include/linux/rds.h:155:2: error: unknown type name 'uint32_t'
  uint32_t   last_sent_nxt;
/usr/include/linux/rds.h:156:2: error: unknown type name 'uint32_t'
  uint32_t   last_expected_una;
/usr/include/linux/rds.h:157:2: error: unknown type name 'uint32_t'
  uint32_t   last_seen_una;
/usr/include/linux/rds.h:164:2: error: unknown type name 'uint8_t'
  uint8_t  src_gid[RDS_IB_GID_LEN];
/usr/include/linux/rds.h:165:2: error: unknown type name 'uint8_t'
  uint8_t  dst_gid[RDS_IB_GID_LEN];
/usr/include/linux/rds.h:167:2: error: unknown type name 'uint32_t'
  uint32_t max_send_wr;
/usr/include/linux/rds.h:168:2: error: unknown type name 'uint32_t'
  uint32_t max_recv_wr;
/usr/include/linux/rds.h:169:2: error: unknown type name 'uint32_t'
  uint32_t max_send_sge;
/usr/include/linux/rds.h:170:2: error: unknown type name 'uint32_t'
  uint32_t rdma_mr_max;
/usr/include/linux/rds.h:171:2: error: unknown type name 'uint32_t'
  uint32_t rdma_mr_size;
/usr/include/linux/rds.h:212:9: error: unknown type name 'uint64_t'
 typedef uint64_t rds_rdma_cookie_t;
/usr/include/linux/rds.h:215:2: error: unknown type name 'uint64_t'
  uint64_t addr;
/usr/include/linux/rds.h:216:2: error: unknown type name 'uint64_t'
  uint64_t bytes;
/usr/include/linux/rds.h:221:2: error: unknown type name 'uint64_t'
  uint64_t cookie_addr;
/usr/include/linux/rds.h:222:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:228:2: error: unknown type name 'uint64_t'
  uint64_t  cookie_addr;
/usr/include/linux/rds.h:229:2: error: unknown type name 'uint64_t'
  uint64_t  flags;
/usr/include/linux/rds.h:234:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:240:2: error: unknown type name 'uint64_t'
  uint64_t local_vec_addr;
/usr/include/linux/rds.h:241:2: error: unknown type name 'uint64_t'
  uint64_t nr_local;
/usr/include/linux/rds.h:242:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:243:2: error: unknown type name 'uint64_t'
  uint64_t user_token;
/usr/include/linux/rds.h:248:2: error: unknown type name 'uint64_t'
  uint64_t  local_addr;
/usr/include/linux/rds.h:249:2: error: unknown type name 'uint64_t'
  uint64_t  remote_addr;
/usr/include/linux/rds.h:252:4: error: unknown type name 'uint64_t'
uint64_t compare;
/usr/include/linux/rds.h:253:4: error: unknown type name 'uint64_t'
uint64_t swap;
/usr/include/linux/rds.h:256:4: error: unknown type name 'uint64_t'
uint64_t add;
/usr/include/linux/rds.h:259:4: error: unknown type name 'uint64_t'
uint64_t compare;
/usr/include/linux/rds.h:260:4: error: unknown type name 'uint64_t'
uint64_t swap;
/usr/include/linux/rds.h:261:4: error: unknown type name 'uint64_t'
uint64_t compare_mask;
/usr/include/linux/rds.h:262:4: error: unknown type name 'uint64_t'
uint64_t swap_mask;
/usr/include/linux/rds.h:265:4: error: unknown type name 'uint64_t'
uint64_t add;
/usr/include/linux/rds.h:266:4: error: unknown type name 'uint64_t'
uint64_t nocarry_mask;
/usr/include/linux/rds.h:269:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:270:2: error: unknown type name 'uint64_t'
  uint64_t user_token;
/usr/include/linux/rds.h:274:2: error: unknown type name 'uint64_t'
  uint64_t user_token;
/usr/include/linux/rds.h:275:2: error: unknown type name 'int32_t'
  int32_t  status;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/rds.h | 102 +++
 1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/include/uapi/linux/rds.h b/include/uapi/linux

[PATCH 2/2] uapi: fix linux/rds.h userspace compilation error

2017-02-15 Thread Dmitry V. Levin
On the kernel side, sockaddr_storage is #define'd to
__kernel_sockaddr_storage.  Replacing struct sockaddr_storage with
struct __kernel_sockaddr_storage defined by  fixes
the following linux/rds.h userspace compilation error:

/usr/include/linux/rds.h:226:26: error: field 'dest_addr' has incomplete type
  struct sockaddr_storage dest_addr;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/rds.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/rds.h b/include/uapi/linux/rds.h
index 3ff5cc2..804c9b2 100644
--- a/include/uapi/linux/rds.h
+++ b/include/uapi/linux/rds.h
@@ -35,6 +35,7 @@
 #define _LINUX_RDS_H
 
 #include 
+#include   /* For __kernel_sockaddr_storage. */
 
 #define RDS_IB_ABI_VERSION 0x301
 
@@ -223,7 +224,7 @@ struct rds_get_mr_args {
 };
 
 struct rds_get_mr_for_dest_args {
-   struct sockaddr_storage dest_addr;
+   struct __kernel_sockaddr_storage dest_addr;
struct rds_iovecvec;
__u64   cookie_addr;
__u64   flags;
-- 
ldv


[PATCH v2] btrfs: remove btrfs_err_str function from uapi/linux/btrfs.h

2017-02-15 Thread Dmitry V. Levin
btrfs_err_str function is not called from anywhere and is replicated
in the userspace headers for btrfs-progs.

It's removal also fixes the following linux/btrfs.h userspace
compilation error:

/usr/include/linux/btrfs.h: In function 'btrfs_err_str':
/usr/include/linux/btrfs.h:740:11: error: 'NULL' undeclared (first use in this 
function)
return NULL;

Suggested-by: Jeff Mahoney 
Signed-off-by: Dmitry V. Levin 
---
v2: remove btrfs_err_str rather than fix it

 include/uapi/linux/btrfs.h | 27 ---
 1 file changed, 27 deletions(-)

diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index db4c253..dcfc3a5 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -713,33 +713,6 @@ enum btrfs_err_code {
BTRFS_ERROR_DEV_ONLY_WRITABLE,
BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
 };
-/* An error code to error string mapping for the kernel
-*  error codes
-*/
-static inline char *btrfs_err_str(enum btrfs_err_code err_code)
-{
-   switch (err_code) {
-   case BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET:
-   return "unable to go below two devices on raid1";
-   case BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET:
-   return "unable to go below four devices on raid10";
-   case BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET:
-   return "unable to go below two devices on raid5";
-   case BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET:
-   return "unable to go below three devices on raid6";
-   case BTRFS_ERROR_DEV_TGT_REPLACE:
-   return "unable to remove the dev_replace target dev";
-   case BTRFS_ERROR_DEV_MISSING_NOT_FOUND:
-   return "no missing devices found to remove";
-   case BTRFS_ERROR_DEV_ONLY_WRITABLE:
-   return "unable to remove the only writeable device";
-   case BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS:
-   return "add/delete/balance/replace/resize operation "\
-   "in progress";
-   default:
-   return NULL;
-   }
-}
 
 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
   struct btrfs_ioctl_vol_args)
-- 
ldv


[PATCH v2] uapi: fix linux/mroute6.h userspace compilation errors

2017-02-16 Thread Dmitry V. Levin
Include  to fix the following linux/mroute6.h userspace
compilation errors:

/usr/include/linux/mroute6.h:80:22: error: field 'mf6cc_origin' has incomplete 
type
  struct sockaddr_in6 mf6cc_origin;  /* Origin of mcast */
/usr/include/linux/mroute6.h:81:22: error: field 'mf6cc_mcastgrp' has 
incomplete type
  struct sockaddr_in6 mf6cc_mcastgrp;  /* Group in question */
/usr/include/linux/mroute6.h:91:22: error: field 'src' has incomplete type
  struct sockaddr_in6 src;
/usr/include/linux/mroute6.h:92:22: error: field 'grp' has incomplete type
  struct sockaddr_in6 grp;
/usr/include/linux/mroute6.h:132:18: error: field 'im6_src' has incomplete type
  struct in6_addr im6_src, im6_dst;
/usr/include/linux/mroute6.h:132:27: error: field 'im6_dst' has incomplete type
  struct in6_addr im6_src, im6_dst;

Signed-off-by: Dmitry V. Levin 
---
v2: Cc'ed netdev

 include/uapi/linux/mroute6.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/mroute6.h b/include/uapi/linux/mroute6.h
index 5062fb5..ed57211 100644
--- a/include/uapi/linux/mroute6.h
+++ b/include/uapi/linux/mroute6.h
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include  /* For struct sockaddr_in6. */
 
 /*
  * Based on the MROUTING 3.5 defines primarily to keep
-- 
ldv


[PATCH v2] uapi: fix linux/ipv6_route.h userspace compilation errors

2017-02-16 Thread Dmitry V. Levin
Include  to fix the following linux/ipv6_route.h userspace
compilation errors:

/usr/include/linux/ipv6_route.h:42:19: error: field 'rtmsg_dst' has incomplete 
type
  struct in6_addr  rtmsg_dst;
/usr/include/linux/ipv6_route.h:43:19: error: field 'rtmsg_src' has incomplete 
type
  struct in6_addr  rtmsg_src;
/ust/include/linux/ipv6_route.h:44:19: error: field 'rtmsg_gateway' has 
incomplete type
  struct in6_addr  rtmsg_gateway;

Signed-off-by: Dmitry V. Levin 
---
v2: Cc'ed netdev

 include/uapi/linux/ipv6_route.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/ipv6_route.h b/include/uapi/linux/ipv6_route.h
index f6598d1..85bbb17 100644
--- a/include/uapi/linux/ipv6_route.h
+++ b/include/uapi/linux/ipv6_route.h
@@ -14,6 +14,7 @@
 #define _UAPI_LINUX_IPV6_ROUTE_H
 
 #include 
+#include  /* For struct in6_addr. */
 
 #define RTF_DEFAULT0x0001  /* default - learned via ND */
 #define RTF_ALLONLINK  0x0002  /* (deprecated and will be removed)
-- 
ldv


[PATCH v2] uapi: fix linux/mroute.h userspace compilation errors

2017-02-16 Thread Dmitry V. Levin
Include  to fix the following linux/mroute.h userspace
compilation errors:

/usr/include/linux/mroute.h:58:18: error: field 'vifc_lcl_addr' has incomplete 
type
  struct in_addr vifc_lcl_addr; /* Local interface address */
/usr/include/linux/mroute.h:61:17: error: field 'vifc_rmt_addr' has incomplete 
type
  struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
/usr/include/linux/mroute.h:72:17: error: field 'mfcc_origin' has incomplete 
type
  struct in_addr mfcc_origin;  /* Origin of mcast */
/usr/include/linux/mroute.h:73:17: error: field 'mfcc_mcastgrp' has incomplete 
type
  struct in_addr mfcc_mcastgrp;  /* Group in question */
/usr/include/linux/mroute.h:84:17: error: field 'src' has incomplete type
  struct in_addr src;
/usr/include/linux/mroute.h:85:17: error: field 'grp' has incomplete type
  struct in_addr grp;
/usr/include/linux/mroute.h:109:17: error: field 'im_src' has incomplete type
  struct in_addr im_src,im_dst;
/usr/include/linux/mroute.h:109:24: error: field 'im_dst' has incomplete type
  struct in_addr im_src,im_dst;

Signed-off-by: Dmitry V. Levin 
---
v2: Cc'ed netdev

 include/uapi/linux/mroute.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/mroute.h b/include/uapi/linux/mroute.h
index cf94301..1fe4c1e 100644
--- a/include/uapi/linux/mroute.h
+++ b/include/uapi/linux/mroute.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include   /* For struct in_addr. */
 
 /* Based on the MROUTING 3.5 defines primarily to keep
  * source compatibility with BSD.
-- 
ldv


[PATCH v2 1/2] uapi: fix linux/rds.h userspace compilation errors

2017-02-16 Thread Dmitry V. Levin
Consistently use types from linux/types.h to fix the following
linux/rds.h userspace compilation errors:

/usr/include/linux/rds.h:106:2: error: unknown type name 'uint8_t'
  uint8_t name[32];
/usr/include/linux/rds.h:107:2: error: unknown type name 'uint64_t'
  uint64_t value;
/usr/include/linux/rds.h:117:2: error: unknown type name 'uint64_t'
  uint64_t next_tx_seq;
/usr/include/linux/rds.h:118:2: error: unknown type name 'uint64_t'
  uint64_t next_rx_seq;
/usr/include/linux/rds.h:121:2: error: unknown type name 'uint8_t'
  uint8_t transport[TRANSNAMSIZ];  /* null term ascii */
/usr/include/linux/rds.h:122:2: error: unknown type name 'uint8_t'
  uint8_t flags;
/usr/include/linux/rds.h:129:2: error: unknown type name 'uint64_t'
  uint64_t seq;
/usr/include/linux/rds.h:130:2: error: unknown type name 'uint32_t'
  uint32_t len;
/usr/include/linux/rds.h:135:2: error: unknown type name 'uint8_t'
  uint8_t flags;
/usr/include/linux/rds.h:139:2: error: unknown type name 'uint32_t'
  uint32_t sndbuf;
/usr/include/linux/rds.h:144:2: error: unknown type name 'uint32_t'
  uint32_t rcvbuf;
/usr/include/linux/rds.h:145:2: error: unknown type name 'uint64_t'
  uint64_t inum;
/usr/include/linux/rds.h:153:2: error: unknown type name 'uint64_t'
  uint64_t   hdr_rem;
/usr/include/linux/rds.h:154:2: error: unknown type name 'uint64_t'
  uint64_t   data_rem;
/usr/include/linux/rds.h:155:2: error: unknown type name 'uint32_t'
  uint32_t   last_sent_nxt;
/usr/include/linux/rds.h:156:2: error: unknown type name 'uint32_t'
  uint32_t   last_expected_una;
/usr/include/linux/rds.h:157:2: error: unknown type name 'uint32_t'
  uint32_t   last_seen_una;
/usr/include/linux/rds.h:164:2: error: unknown type name 'uint8_t'
  uint8_t  src_gid[RDS_IB_GID_LEN];
/usr/include/linux/rds.h:165:2: error: unknown type name 'uint8_t'
  uint8_t  dst_gid[RDS_IB_GID_LEN];
/usr/include/linux/rds.h:167:2: error: unknown type name 'uint32_t'
  uint32_t max_send_wr;
/usr/include/linux/rds.h:168:2: error: unknown type name 'uint32_t'
  uint32_t max_recv_wr;
/usr/include/linux/rds.h:169:2: error: unknown type name 'uint32_t'
  uint32_t max_send_sge;
/usr/include/linux/rds.h:170:2: error: unknown type name 'uint32_t'
  uint32_t rdma_mr_max;
/usr/include/linux/rds.h:171:2: error: unknown type name 'uint32_t'
  uint32_t rdma_mr_size;
/usr/include/linux/rds.h:212:9: error: unknown type name 'uint64_t'
 typedef uint64_t rds_rdma_cookie_t;
/usr/include/linux/rds.h:215:2: error: unknown type name 'uint64_t'
  uint64_t addr;
/usr/include/linux/rds.h:216:2: error: unknown type name 'uint64_t'
  uint64_t bytes;
/usr/include/linux/rds.h:221:2: error: unknown type name 'uint64_t'
  uint64_t cookie_addr;
/usr/include/linux/rds.h:222:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:228:2: error: unknown type name 'uint64_t'
  uint64_t  cookie_addr;
/usr/include/linux/rds.h:229:2: error: unknown type name 'uint64_t'
  uint64_t  flags;
/usr/include/linux/rds.h:234:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:240:2: error: unknown type name 'uint64_t'
  uint64_t local_vec_addr;
/usr/include/linux/rds.h:241:2: error: unknown type name 'uint64_t'
  uint64_t nr_local;
/usr/include/linux/rds.h:242:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:243:2: error: unknown type name 'uint64_t'
  uint64_t user_token;
/usr/include/linux/rds.h:248:2: error: unknown type name 'uint64_t'
  uint64_t  local_addr;
/usr/include/linux/rds.h:249:2: error: unknown type name 'uint64_t'
  uint64_t  remote_addr;
/usr/include/linux/rds.h:252:4: error: unknown type name 'uint64_t'
uint64_t compare;
/usr/include/linux/rds.h:253:4: error: unknown type name 'uint64_t'
uint64_t swap;
/usr/include/linux/rds.h:256:4: error: unknown type name 'uint64_t'
uint64_t add;
/usr/include/linux/rds.h:259:4: error: unknown type name 'uint64_t'
uint64_t compare;
/usr/include/linux/rds.h:260:4: error: unknown type name 'uint64_t'
uint64_t swap;
/usr/include/linux/rds.h:261:4: error: unknown type name 'uint64_t'
uint64_t compare_mask;
/usr/include/linux/rds.h:262:4: error: unknown type name 'uint64_t'
uint64_t swap_mask;
/usr/include/linux/rds.h:265:4: error: unknown type name 'uint64_t'
uint64_t add;
/usr/include/linux/rds.h:266:4: error: unknown type name 'uint64_t'
uint64_t nocarry_mask;
/usr/include/linux/rds.h:269:2: error: unknown type name 'uint64_t'
  uint64_t flags;
/usr/include/linux/rds.h:270:2: error: unknown type name 'uint64_t'
  uint64_t user_token;
/usr/include/linux/rds.h:274:2: error: unknown type name 'uint64_t'
  uint64_t user_token;
/usr/include/linux/rds.h:275:2: error: unknown type name 'int32_t'
  int32_t  status;

Signed-off-by: Dmitry V. Levin 
---
v2: Cc'ed netdev

 include/uapi/linux/rds.h | 102 +++
 1 file changed, 51 insertions(+), 51 deletions(-)

diff --git a/include/uapi/linux/rds.h b

[PATCH v2 2/2] uapi: fix linux/rds.h userspace compilation error

2017-02-16 Thread Dmitry V. Levin
On the kernel side, sockaddr_storage is #define'd to
__kernel_sockaddr_storage.  Replacing struct sockaddr_storage with
struct __kernel_sockaddr_storage defined by  fixes
the following linux/rds.h userspace compilation error:

/usr/include/linux/rds.h:226:26: error: field 'dest_addr' has incomplete type
  struct sockaddr_storage dest_addr;

Signed-off-by: Dmitry V. Levin 
---
v2: Cc'ed netdev

 include/uapi/linux/rds.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/rds.h b/include/uapi/linux/rds.h
index 3ff5cc2..804c9b2 100644
--- a/include/uapi/linux/rds.h
+++ b/include/uapi/linux/rds.h
@@ -35,6 +35,7 @@
 #define _LINUX_RDS_H
 
 #include 
+#include   /* For __kernel_sockaddr_storage. */
 
 #define RDS_IB_ABI_VERSION 0x301
 
@@ -223,7 +224,7 @@ struct rds_get_mr_args {
 };
 
 struct rds_get_mr_for_dest_args {
-   struct sockaddr_storage dest_addr;
+   struct __kernel_sockaddr_storage dest_addr;
struct rds_iovecvec;
__u64   cookie_addr;
__u64   flags;
-- 
ldv


[PATCH] uapi: fix linux/if.h userspace compilation errors

2017-02-20 Thread Dmitry V. Levin
Include  (guarded by ifndef __KERNEL__) to fix
the following linux/if.h userspace compilation errors:

/usr/include/linux/if.h:234:19: error: field 'ifru_addr' has incomplete type
   struct sockaddr ifru_addr;
/usr/include/linux/if.h:235:19: error: field 'ifru_dstaddr' has incomplete type
   struct sockaddr ifru_dstaddr;
/usr/include/linux/if.h:236:19: error: field 'ifru_broadaddr' has incomplete 
type
   struct sockaddr ifru_broadaddr;
/usr/include/linux/if.h:237:19: error: field 'ifru_netmask' has incomplete type
   struct sockaddr ifru_netmask;
/usr/include/linux/if.h:238:20: error: field 'ifru_hwaddr' has incomplete type
   struct  sockaddr ifru_hwaddr;

This also fixes userspace compilation of the following uapi headers:
  linux/atmbr2684.h
  linux/gsmmux.h
  linux/if_arp.h
  linux/if_bonding.h
  linux/if_frad.h
  linux/if_pppox.h
  linux/if_tunnel.h
  linux/netdevice.h
  linux/route.h
  linux/wireless.h

As no uapi header provides a definition of struct sockaddr, inclusion
of  seems to be the most conservative and the only safe
fix available.

All current users of  are very likely to be including
 already because the latter is the sole provider
of struct sockaddr definition in libc, so adding a uapi header
with a definition of struct sockaddr would create a potential
conflict with .

Replacing struct sockaddr in the definition of struct ifreq with
a different type would create a potential incompatibility with current
users of struct ifreq who might rely on ifru_addr et al members being
of type struct sockaddr.

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/if.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/uapi/linux/if.h b/include/uapi/linux/if.h
index 1158a04..259617a 100644
--- a/include/uapi/linux/if.h
+++ b/include/uapi/linux/if.h
@@ -24,6 +24,10 @@
 #include   /* for "struct sockaddr" et al  */
 #include /* for "__user" et al   */
 
+#ifndef __KERNEL__
+#include /* for struct sockaddr. 
*/
+#endif
+
 #if __UAPI_DEF_IF_IFNAMSIZ
 #defineIFNAMSIZ16
 #endif /* __UAPI_DEF_IF_IFNAMSIZ */
-- 
ldv


Re: + uapi-fix-linux-sysctlh-userspace-compilation-errors.patch added to -mm tree

2017-02-24 Thread Dmitry V. Levin
On Fri, Feb 24, 2017 at 05:35:33PM +0300, Alexey Dobriyan wrote:
> On Thu, Feb 23, 2017 at 02:44:31PM -0800, a...@linux-foundation.org wrote:
> > /usr/include/linux/sysctl.h:38:2: error: unknown type name 'size_t'
> >   size_t *oldlenp;
> > /usr/include/linux/sysctl.h:40:2: error: unknown type name 'size_t'
> >   size_t newlen;
> 
> > --- 
> > a/include/uapi/linux/sysctl.h~uapi-fix-linux-sysctlh-userspace-compilation-errors
> > +++ a/include/uapi/linux/sysctl.h
> > @@ -26,6 +26,10 @@
> >  #include 
> >  #include 
> >  
> > +#ifndef __KERNEL__
> > +#include /* For size_t. */
> > +#endif
> 
> There is __kernel_size_t for cases like this.

No, __kernel_size_t is not for cases like this because size_t differs
from __kernel_size_t on x32 and mips n32.

Fortunately, there is no sysctl syscall entry on x32, but on mips m32
it is there with number 6152, implemented using compat_sys_sysctl.
The latter operates with argument of type struct compat_sysctl_args*
where newlen is of type compat_size_t.

If you change it from size_t to __kernel_size_t, you'll break mips n32.


-- 
ldv


pgpNWnL38KPKb.pgp
Description: PGP signature


[PATCH] uapi: fix drm/omap_drm.h userspace compilation errors

2017-02-25 Thread Dmitry V. Levin
Consistently use types from linux/types.h like in other uapi drm/*_drm.h
header files to fix the following drm/omap_drm.h userspace compilation
errors:

/usr/include/drm/omap_drm.h:36:2: error: unknown type name 'uint64_t'
  uint64_t param;   /* in */
/usr/include/drm/omap_drm.h:37:2: error: unknown type name 'uint64_t'
  uint64_t value;   /* in (set_param), out (get_param) */
/usr/include/drm/omap_drm.h:56:2: error: unknown type name 'uint32_t'
  uint32_t bytes;  /* (for non-tiled formats) */
/usr/include/drm/omap_drm.h:58:3: error: unknown type name 'uint16_t'
   uint16_t width;
/usr/include/drm/omap_drm.h:59:3: error: unknown type name 'uint16_t'
   uint16_t height;
/usr/include/drm/omap_drm.h:65:2: error: unknown type name 'uint32_t'
  uint32_t flags;   /* in */
/usr/include/drm/omap_drm.h:66:2: error: unknown type name 'uint32_t'
  uint32_t handle;  /* out */
/usr/include/drm/omap_drm.h:67:2: error: unknown type name 'uint32_t'
  uint32_t __pad;
/usr/include/drm/omap_drm.h:77:2: error: unknown type name 'uint32_t'
  uint32_t handle;  /* buffer handle (in) */
/usr/include/drm/omap_drm.h:78:2: error: unknown type name 'uint32_t'
  uint32_t op;   /* mask of omap_gem_op (in) */
/usr/include/drm/omap_drm.h:82:2: error: unknown type name 'uint32_t'
  uint32_t handle;  /* buffer handle (in) */
/usr/include/drm/omap_drm.h:83:2: error: unknown type name 'uint32_t'
  uint32_t op;   /* mask of omap_gem_op (in) */
/usr/include/drm/omap_drm.h:88:2: error: unknown type name 'uint32_t'
  uint32_t nregions;
/usr/include/drm/omap_drm.h:89:2: error: unknown type name 'uint32_t'
  uint32_t __pad;
/usr/include/drm/omap_drm.h:93:2: error: unknown type name 'uint32_t'
  uint32_t handle;  /* buffer handle (in) */
/usr/include/drm/omap_drm.h:94:2: error: unknown type name 'uint32_t'
  uint32_t pad;
/usr/include/drm/omap_drm.h:95:2: error: unknown type name 'uint64_t'
  uint64_t offset;  /* mmap offset (out) */
/usr/include/drm/omap_drm.h:102:2: error: unknown type name 'uint32_t'
  uint32_t size;   /* virtual size for mmap'ing (out) */
/usr/include/drm/omap_drm.h:103:2: error: unknown type name 'uint32_t'
  uint32_t __pad;

Fixes: ef6503e89194 ("drm: Kbuild: add omap_drm.h to the installed headers")
Signed-off-by: Dmitry V. Levin 
---
 include/uapi/drm/omap_drm.h | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/include/uapi/drm/omap_drm.h b/include/uapi/drm/omap_drm.h
index 407cb55..7fb9786 100644
--- a/include/uapi/drm/omap_drm.h
+++ b/include/uapi/drm/omap_drm.h
@@ -33,8 +33,8 @@ extern "C" {
 #define OMAP_PARAM_CHIPSET_ID  1   /* ie. 0x3430, 0x4430, etc */
 
 struct drm_omap_param {
-   uint64_t param; /* in */
-   uint64_t value; /* in (set_param), out (get_param) */
+   __u64 param;/* in */
+   __u64 value;/* in (set_param), out (get_param) */
 };
 
 #define OMAP_BO_SCANOUT0x0001  /* scanout capable 
(phys contiguous) */
@@ -53,18 +53,18 @@ struct drm_omap_param {
 #define OMAP_BO_TILED  (OMAP_BO_TILED_8 | OMAP_BO_TILED_16 | 
OMAP_BO_TILED_32)
 
 union omap_gem_size {
-   uint32_t bytes; /* (for non-tiled formats) */
+   __u32 bytes;/* (for non-tiled formats) */
struct {
-   uint16_t width;
-   uint16_t height;
+   __u16 width;
+   __u16 height;
} tiled;/* (for tiled formats) */
 };
 
 struct drm_omap_gem_new {
union omap_gem_size size;   /* in */
-   uint32_t flags; /* in */
-   uint32_t handle;/* out */
-   uint32_t __pad;
+   __u32 flags;/* in */
+   __u32 handle;   /* out */
+   __u32 __pad;
 };
 
 /* mask of operations: */
@@ -74,33 +74,33 @@ enum omap_gem_op {
 };
 
 struct drm_omap_gem_cpu_prep {
-   uint32_t handle;/* buffer handle (in) */
-   uint32_t op;/* mask of omap_gem_op (in) */
+   __u32 handle;   /* buffer handle (in) */
+   __u32 op;   /* mask of omap_gem_op (in) */
 };
 
 struct drm_omap_gem_cpu_fini {
-   uint32_t handle;/* buffer handle (in) */
-   uint32_t op;/* mask of omap_gem_op (in) */
+   __u32 handle;   /* buffer handle (in) */
+   __u32 op;   /* mask of omap_gem_op (in) */
/* TODO maybe here we pass down info about what regions are touched
 * by sw so we can be clever about cache ops?  For now a placeholder,
 * set to zero and we just do full buffer flush..
 */
-   uint32_t nregions;
-   uint32_t __pad;
+   __u32 nregions;
+   __u32 __pad;
 };
 
 struct drm_omap_gem_info {
-   uint32_t handle;/* buffer handle (in) */
-   uint32_t pad;
-  

[PATCH] uapi: fix asm/signal.h userspace compilation errors

2017-02-25 Thread Dmitry V. Levin
Include  (guarded by #ifndef __KERNEL__) to fix asm/signal.h
userspace compilation errors like this:

/usr/include/asm/signal.h:126:2: error: unknown type name 'size_t'
  size_t ss_size;

As no uapi header provides a definition of size_t, inclusion
of  seems to be the most conservative fix available.

On the kernel side size_t is typedef'ed to __kernel_size_t, so
an alternative fix would be to change the type of sigaltstack.ss_size
from size_t to __kernel_size_t for all architectures except those where
sizeof(size_t) < sizeof(__kernel_size_t), namely, x32 and mips n32.

On x32 and mips n32, however, #include  seems to be the most
straightforward way to obtain the definition for sigaltstack.ss_size's
type.

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/signal.h  | 3 +++
 arch/alpha/include/uapi/asm/signal.h   | 3 +++
 arch/arm/include/uapi/asm/signal.h | 3 +++
 arch/avr32/include/uapi/asm/signal.h   | 3 +++
 arch/cris/include/uapi/asm/signal.h| 3 +++
 arch/h8300/include/uapi/asm/signal.h   | 3 +++
 arch/ia64/include/uapi/asm/signal.h| 4 
 arch/m32r/include/uapi/asm/signal.h| 3 +++
 arch/m68k/include/uapi/asm/signal.h| 3 +++
 arch/mips/include/uapi/asm/signal.h| 3 +++
 arch/mn10300/include/uapi/asm/signal.h | 3 +++
 arch/parisc/include/uapi/asm/signal.h  | 4 
 arch/powerpc/include/uapi/asm/signal.h | 3 +++
 arch/s390/include/uapi/asm/signal.h| 3 +++
 arch/sparc/include/uapi/asm/signal.h   | 3 +++
 arch/x86/include/uapi/asm/signal.h | 3 +++
 arch/xtensa/include/uapi/asm/signal.h  | 2 ++
 17 files changed, 52 insertions(+)

diff --git a/include/uapi/asm-generic/signal.h 
b/include/uapi/asm-generic/signal.h
index 3094618..e618eab 100644
--- a/include/uapi/asm-generic/signal.h
+++ b/include/uapi/asm-generic/signal.h
@@ -100,6 +100,9 @@ typedef unsigned long old_sigset_t;
 #endif
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 struct sigaction {
__sighandler_t sa_handler;
unsigned long sa_flags;
diff --git a/arch/alpha/include/uapi/asm/signal.h 
b/arch/alpha/include/uapi/asm/signal.h
index dd4ca4bc..74e09f6 100644
--- a/arch/alpha/include/uapi/asm/signal.h
+++ b/arch/alpha/include/uapi/asm/signal.h
@@ -94,6 +94,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/arm/include/uapi/asm/signal.h 
b/arch/arm/include/uapi/asm/signal.h
index 33073bd..a7b0012 100644
--- a/arch/arm/include/uapi/asm/signal.h
+++ b/arch/arm/include/uapi/asm/signal.h
@@ -93,6 +93,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/avr32/include/uapi/asm/signal.h 
b/arch/avr32/include/uapi/asm/signal.h
index ffe8c77..62f3b88 100644
--- a/arch/avr32/include/uapi/asm/signal.h
+++ b/arch/avr32/include/uapi/asm/signal.h
@@ -95,6 +95,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/cris/include/uapi/asm/signal.h 
b/arch/cris/include/uapi/asm/signal.h
index ce42fa7..bedff78 100644
--- a/arch/cris/include/uapi/asm/signal.h
+++ b/arch/cris/include/uapi/asm/signal.h
@@ -89,6 +89,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/h8300/include/uapi/asm/signal.h 
b/arch/h8300/include/uapi/asm/signal.h
index af3a6c3..361e2e5 100644
--- a/arch/h8300/include/uapi/asm/signal.h
+++ b/arch/h8300/include/uapi/asm/signal.h
@@ -88,6 +88,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/ia64/include/uapi/asm/signal.h 
b/arch/ia64/include/uapi/asm/signal.h
index c0ea285..b089bfc 100644
--- a/arch/ia64/include/uapi/asm/signal.h
+++ b/arch/ia64/include/uapi/asm/signal.h
@@ -107,6 +107,10 @@
 
 #  include 
 
+#  ifndef __KERNEL__
+#   include  /* For size_t. */
+#  endif
+
 /* Avoid too many header ordering problems.  */
 struct siginfo;
 
diff --git a/arch/m32r/include/uapi/asm/signal.h 
b/arch/m32r/include/uapi/asm/signal.h
index 54acacb..269ec39 100644
--- a/arch/m32r/include/uapi/asm/signal.h
+++ b/arch/m32r/include/uapi/asm/signal.h
@@ -90,6 +90,9 @@ typedef unsigned long sigset_t;
 #include 
 
 #ifndef __KERNEL__
+
+#include /* For size_t. */
+
 /* Here we must cater to libcs that poke about in kernel headers.  */
 
 struct sigaction {
diff --git a/arch/m68k/include/uapi/asm/signal.h 
b/arch/m68k/include/uapi/asm/signal.h
index cba6f85..f6a409e 100

[PATCH] uapi: fix asm/ipcbuf.h userspace compilation errors

2017-02-26 Thread Dmitry V. Levin
Include  to fix asm/ipcbuf.h userspace compilation
errors like this:

/usr/include/asm-generic/ipcbuf.h:20:2: error: unknown type name 
'__kernel_key_t'
  __kernel_key_t  key;
/usr/include/asm-generic/ipcbuf.h:21:2: error: unknown type name 
'__kernel_uid32_t'
  __kernel_uid32_t uid;
/usr/include/asm-generic/ipcbuf.h:22:2: error: unknown type name 
'__kernel_gid32_t'
  __kernel_gid32_t gid;
/usr/include/asm-generic/ipcbuf.h:23:2: error: unknown type name 
'__kernel_uid32_t'
  __kernel_uid32_t cuid;
/usr/include/asm-generic/ipcbuf.h:24:2: error: unknown type name 
'__kernel_gid32_t'
  __kernel_gid32_t cgid;
/usr/include/asm-generic/ipcbuf.h:25:2: error: unknown type name 
'__kernel_mode_t'
  __kernel_mode_t  mode;
/usr/include/asm-generic/ipcbuf.h:27:35: error: '__kernel_mode_t' undeclared 
here (not in a function)
  unsigned char  __pad1[4 - sizeof(__kernel_mode_t)];
/usr/include/asm-generic/ipcbuf.h:30:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused1;
/usr/include/asm-generic/ipcbuf.h:31:2: error: unknown type name 
'__kernel_ulong_t'
  __kernel_ulong_t __unused2;

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/ipcbuf.h | 2 ++
 arch/s390/include/uapi/asm/ipcbuf.h   | 2 ++
 arch/sparc/include/uapi/asm/ipcbuf.h  | 2 ++
 arch/xtensa/include/uapi/asm/ipcbuf.h | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/include/uapi/asm-generic/ipcbuf.h 
b/include/uapi/asm-generic/ipcbuf.h
index 3dbcc1e..909f825 100644
--- a/include/uapi/asm-generic/ipcbuf.h
+++ b/include/uapi/asm-generic/ipcbuf.h
@@ -1,6 +1,8 @@
 #ifndef __ASM_GENERIC_IPCBUF_H
 #define __ASM_GENERIC_IPCBUF_H
 
+#include 
+
 /*
  * The generic ipc64_perm structure:
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/s390/include/uapi/asm/ipcbuf.h 
b/arch/s390/include/uapi/asm/ipcbuf.h
index 37f293d..9f1185c 100644
--- a/arch/s390/include/uapi/asm/ipcbuf.h
+++ b/arch/s390/include/uapi/asm/ipcbuf.h
@@ -1,6 +1,8 @@
 #ifndef __S390_IPCBUF_H__
 #define __S390_IPCBUF_H__
 
+#include 
+
 /*
  * The user_ipc_perm structure for S/390 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/sparc/include/uapi/asm/ipcbuf.h 
b/arch/sparc/include/uapi/asm/ipcbuf.h
index 66013b4..b7b1bcb 100644
--- a/arch/sparc/include/uapi/asm/ipcbuf.h
+++ b/arch/sparc/include/uapi/asm/ipcbuf.h
@@ -1,6 +1,8 @@
 #ifndef __SPARC_IPCBUF_H
 #define __SPARC_IPCBUF_H
 
+#include 
+
 /*
  * The ipc64_perm structure for sparc/sparc64 architecture.
  * Note extra padding because this structure is passed back and forth
diff --git a/arch/xtensa/include/uapi/asm/ipcbuf.h 
b/arch/xtensa/include/uapi/asm/ipcbuf.h
index c33aa6a..7442e48 100644
--- a/arch/xtensa/include/uapi/asm/ipcbuf.h
+++ b/arch/xtensa/include/uapi/asm/ipcbuf.h
@@ -11,6 +11,8 @@
 #ifndef _XTENSA_IPCBUF_H
 #define _XTENSA_IPCBUF_H
 
+#include 
+
 /*
  * Pad space is left for:
  * - 32-bit mode_t and seq
-- 
ldv


Re: + uapi-fix-linux-sysctlh-userspace-compilation-errors.patch added to -mm tree

2017-02-27 Thread Dmitry V. Levin
On Mon, Feb 27, 2017 at 12:38:16PM +0300, Alexey Dobriyan wrote:
> On Sat, Feb 25, 2017 at 1:35 AM, Dmitry V. Levin  wrote:
> > On Fri, Feb 24, 2017 at 05:35:33PM +0300, Alexey Dobriyan wrote:
> >> On Thu, Feb 23, 2017 at 02:44:31PM -0800, a...@linux-foundation.org wrote:
> >> > /usr/include/linux/sysctl.h:38:2: error: unknown type name 'size_t'
> >> >   size_t *oldlenp;
> >> > /usr/include/linux/sysctl.h:40:2: error: unknown type name 'size_t'
> >> >   size_t newlen;
> >>
> >> > --- 
> >> > a/include/uapi/linux/sysctl.h~uapi-fix-linux-sysctlh-userspace-compilation-errors
> >> > +++ a/include/uapi/linux/sysctl.h
> >> > @@ -26,6 +26,10 @@
> >> >  #include 
> >> >  #include 
> >> >
> >> > +#ifndef __KERNEL__
> >> > +#include /* For size_t. */
> >> > +#endif
> >>
> >> There is __kernel_size_t for cases like this.
> >
> > No, __kernel_size_t is not for cases like this because size_t differs
> > from __kernel_size_t on x32 and mips n32.
> >
> > Fortunately, there is no sysctl syscall entry on x32, but on mips m32
> > it is there with number 6152, implemented using compat_sys_sysctl.
> > The latter operates with argument of type struct compat_sysctl_args*
> > where newlen is of type compat_size_t.
> >
> > If you change it from size_t to __kernel_size_t, you'll break mips n32.
> 
> You're gluing kernel interface to an userspace header
> which kernel doesn't control.

Are you sure it's me who does the gluing?

As no uapi header provides a definition of size_t, they are essentially
relying on size_t being provided elsewhere.

For this reason, inclusion of  is the most conservative fix.

> How can this fix anything?

For example,
AC_CHECK_HEADERS([]) doesn't work, one has to use
AC_CHECK_HEADERS([], , , [#include ]) instead.
The same issue arises with other autoconf checks.

I think that every uapi header file should be standalone, i.e. it must
include, directly or indirectly, every definition it uses, so that no user
should have to guess header dependencies.


-- 
ldv


pgpxOLKTbV0AM.pgp
Description: PGP signature


Re: + uapi-fix-linux-sysctlh-userspace-compilation-errors.patch added to -mm tree

2017-02-27 Thread Dmitry V. Levin
On Sat, Feb 25, 2017 at 01:35:51AM +0300, Dmitry V. Levin wrote:
> On Fri, Feb 24, 2017 at 05:35:33PM +0300, Alexey Dobriyan wrote:
> > On Thu, Feb 23, 2017 at 02:44:31PM -0800, a...@linux-foundation.org wrote:
> > > /usr/include/linux/sysctl.h:38:2: error: unknown type name 'size_t'
> > >   size_t *oldlenp;
> > > /usr/include/linux/sysctl.h:40:2: error: unknown type name 'size_t'
> > >   size_t newlen;
> > 
> > > --- 
> > > a/include/uapi/linux/sysctl.h~uapi-fix-linux-sysctlh-userspace-compilation-errors
> > > +++ a/include/uapi/linux/sysctl.h
> > > @@ -26,6 +26,10 @@
> > >  #include 
> > >  #include 
> > >  
> > > +#ifndef __KERNEL__
> > > +#include   /* For size_t. */
> > > +#endif
> > 
> > There is __kernel_size_t for cases like this.
> 
> No, __kernel_size_t is not for cases like this because size_t differs
> from __kernel_size_t on x32 and mips n32.
> 
> Fortunately, there is no sysctl syscall entry on x32, but on mips m32
> it is there with number 6152, implemented using compat_sys_sysctl.
> The latter operates with argument of type struct compat_sysctl_args*
> where newlen is of type compat_size_t.
> 
> If you change it from size_t to __kernel_size_t, you'll break mips n32.

Apparently, my statement that sizeof(size_t) < sizeof(__kernel_size_t)
on mips n32 is not correct, so x32 is the only architecture of this kind.

This means that size_t can be replaced with __kernel_size_t in this
particular case.  Does anybody want that change instead of my original
proposal?


-- 
ldv


pgpUFdKueGtSt.pgp
Description: PGP signature


[RFC PATCH] uapi: move struct reiserfs_security_handle out from linux/reiserfs_xattr.h

2017-02-27 Thread Dmitry V. Levin
As there seems to be no way struct reiserfs_security_handle could be
passed between the kernel and userspace, move its definition from the
UAPI header to a private header fs/reiserfs/xattr.h which is the only
file in the tree that includes linux/reiserfs_xattr.h.

This also fixes the following linux/reiserfs_xattr.h userspace
compilation error:

/usr/include/linux/reiserfs_xattr.h:21:2: error: unknown type name 'size_t'
  size_t length;

Signed-off-by: Dmitry V. Levin 
---
Perhaps the whole file could be moved out from the UAPI.
I'm not sure about that, though.

 fs/reiserfs/xattr.h | 6 ++
 include/uapi/linux/reiserfs_xattr.h | 6 --
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/reiserfs/xattr.h b/fs/reiserfs/xattr.h
index 613ff5a..1ae77ed 100644
--- a/fs/reiserfs/xattr.h
+++ b/fs/reiserfs/xattr.h
@@ -4,6 +4,12 @@
 #include 
 #include 
 
+struct reiserfs_security_handle {
+   const char *name;
+   void *value;
+   size_t length;
+};
+
 struct inode;
 struct dentry;
 struct iattr;
diff --git a/include/uapi/linux/reiserfs_xattr.h 
b/include/uapi/linux/reiserfs_xattr.h
index 38fdd64..e07f4c7 100644
--- a/include/uapi/linux/reiserfs_xattr.h
+++ b/include/uapi/linux/reiserfs_xattr.h
@@ -15,10 +15,4 @@ struct reiserfs_xattr_header {
__le32 h_hash;  /* hash of the value */
 };
 
-struct reiserfs_security_handle {
-   const char *name;
-   void *value;
-   size_t length;
-};
-
 #endif  /*  _LINUX_REISERFS_XATTR_H  */
-- 
ldv


[RFC PATCH] uapi: fix linux/packet_diag.h userspace compilation error

2017-02-27 Thread Dmitry V. Levin
Replace MAX_ADDR_LEN with its numeric value to fix the following
linux/packet_diag.h userspace compilation error:

/usr/include/linux/packet_diag.h:67:17: error: 'MAX_ADDR_LEN' undeclared here 
(not in a function)
  __u8 pdmc_addr[MAX_ADDR_LEN];

This is not the first case in the UAPI where the numeric value
of MAX_ADDR_LEN is used, uapi/linux/if_link.h already does the same,
and there are no UAPI headers besides these two that use MAX_ADDR_LEN.

The alternative fix would be to include  which
pulls in other headers and a lot of definitions with them.

Signed-off-by: Dmitry V. Levin 
---
I'm not quite comfortable with this approach but the alternative
has its own drawbacks.

 include/uapi/linux/packet_diag.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/packet_diag.h b/include/uapi/linux/packet_diag.h
index d08c63f..0c5d5dd 100644
--- a/include/uapi/linux/packet_diag.h
+++ b/include/uapi/linux/packet_diag.h
@@ -64,7 +64,7 @@ struct packet_diag_mclist {
__u32   pdmc_count;
__u16   pdmc_type;
__u16   pdmc_alen;
-   __u8pdmc_addr[MAX_ADDR_LEN];
+   __u8pdmc_addr[32]; /* MAX_ADDR_LEN */
 };
 
 struct packet_diag_ring {
-- 
ldv


Re: [PATCH v7 7/8] uapi: export all headers under uapi directories

2017-02-27 Thread Dmitry V. Levin
On Mon, Feb 27, 2017 at 05:01:55PM +0100, Nicolas Dichtel wrote:
> Le 24/02/2017 à 17:49, Nicolas Dichtel a écrit :
> > Regularly, when a new header is created in include/uapi/, the developer
> > forgets to add it in the corresponding Kbuild file. This error is usually
> > detected after the release is out.
> > 
> > In fact, all headers under uapi directories should be exported, thus it's
> > useless to have an exhaustive list.
> > 
> > After this patch, the following files, which were not exported, are now
> > exported (with make headers_install_all):
> > asm-arc/kvm_para.h
> > asm-arc/ucontext.h
> > asm-avr32/kvm_para.h
> > asm-blackfin/shmparam.h
> > asm-blackfin/ucontext.h
> > asm-c6x/shmparam.h
> > asm-c6x/ucontext.h
> > asm-cris/kvm_para.h
> > asm-h8300/shmparam.h
> > asm-h8300/ucontext.h
> > asm-hexagon/shmparam.h
> > asm-m32r/kvm_para.h
> > asm-m68k/kvm_para.h
> > asm-m68k/shmparam.h
> > asm-metag/kvm_para.h
> > asm-metag/shmparam.h
> > asm-metag/ucontext.h
> > asm-mips/hwcap.h
> > asm-mips/reg.h
> > asm-mips/ucontext.h
> > asm-nios2/kvm_para.h
> > asm-nios2/ucontext.h
> > asm-openrisc/shmparam.h
> > asm-parisc/kvm_para.h
> > asm-powerpc/perf_regs.h
> > asm-sh/kvm_para.h
> > asm-sh/ucontext.h
> > asm-tile/shmparam.h
> > asm-unicore32/shmparam.h
> > asm-unicore32/ucontext.h
> > asm-x86/hwcap2.h
> > asm-xtensa/kvm_para.h
> > drm/armada_drm.h
> > drm/etnaviv_drm.h
> > drm/vgem_drm.h
> > linux/auto_dev-ioctl.h
> > linux/bcache.h
> > linux/btrfs_tree.h
> > linux/cifs
> > linux/cifs/cifs_mount.h
> > linux/coresight-stm.h
> > linux/cryptouser.h
> > linux/genwqe
> > linux/genwqe/genwqe_card.h
> > linux/hash_info.h
> > linux/kcm.h
> > linux/kcov.h
> > linux/kfd_ioctl.h
> > linux/lightnvm.h
> > linux/module.h
> > linux/nilfs2_api.h
> > linux/nilfs2_ondisk.h
> > linux/nsfs.h
> > linux/pr.h
> > linux/qrtr.h
> > linux/rpmsg.h
> > linux/sed-opal.h
> > linux/smc.h
> > linux/smc_diag.h
> > linux/stm.h
> > linux/userio.h
> > linux/wil6210_uapi.h
> > rdma/bnxt_re-abi.h
> > 
> > Note that I have removed from this list the files which are generated in 
> > every
> > exported directories (like .install or .install.cmd).
> > 
> > Thanks to Julien Floret  for the tip to get all
> > subdirs with a pure makefile command.
> > 
> > For the record, note that exported files for asm directories are a mix of
> > files listed by:
> >  - include/uapi/asm-generic/Kbuild.asm;
> >  - arch//include/uapi/asm/Kbuild;
> >  - arch//include/asm/Kbuild.
> > 
> > Signed-off-by: Nicolas Dichtel 
> > Acked-by: Daniel Vetter 
> > Acked-by: Russell King 
> > Acked-by: Mark Salter 
> > Acked-by: Michael Ellerman  (powerpc)
> Is there any chance to get this series in before the rc1?

Note that the following newly exported headers have userspace compilation
errors:

/usr/include/drm/armada_drm.h:26:2: error: unknown type name 'uint32_t'
  uint32_t handle;

/usr/include/linux/btrfs_tree.h:390:12: error: 'BTRFS_UUID_SIZE' undeclared 
here (not in a function)
  __u8 uuid[BTRFS_UUID_SIZE];

/usr/include/linux/cryptouser.h:58:16: error: 'CRYPTO_MAX_ALG_NAME' undeclared 
here (not in a function)
  char cru_name[CRYPTO_MAX_ALG_NAME];

/usr/include/linux/kfd_ioctl.h:33:2: error: unknown type name 'uint32_t'
  uint32_t major_version; /* from KFD */

/usr/include/linux/smc_diag.h:6:27: fatal error: rdma/ib_verbs.h: No such file 
or directory
 #include 

/usr/include/linux/wil6210_uapi.h:73:2: error: unknown type name 'uint32_t'
  uint32_t op; /* enum wil_memio_op */

I think they should be fixed first.


-- 
ldv


pgp3ppldSHIxK.pgp
Description: PGP signature


Re: Revised statx(2) man page for review

2017-04-25 Thread Dmitry V. Levin
On Tue, Apr 25, 2017 at 01:14:26PM +0200, Michael Kerrisk (man-pages) wrote:
[...]
>The file timestamps are structures of the following type:
> 
>struct statx_timestamp {
>__s64 tv_sec;/* Seconds since the Epoch (UNIX time) */
>__s32 tv_nsec;   /* Nanoseconds before or since tv_sec */
>};

Nanoseconds since tv_sec.  The "before tv_sec" is not implemented yet
and I hope nobody is going to implement it for the reasons I mentioned
in https://marc.info/?i=20170422192743.GA17005%40altlinux.org


-- 
ldv


signature.asc
Description: PGP signature


[PATCH v2] uapi: change the type of struct statx_timestamp.tv_nsec to unsigned

2017-04-26 Thread Dmitry V. Levin
The comment asserting that the value of struct statx_timestamp.tv_nsec
must be negative when statx_timestamp.tv_sec is negative, is wrong, as
could be seen from the following example:

#define _FILE_OFFSET_BITS 64
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main(void)
{
static const struct timespec ts[2] = {
{ .tv_nsec = UTIME_OMIT },
{ .tv_sec = -2, .tv_nsec = 42 }
};
assert(utimensat(AT_FDCWD, ".", ts, 0) == 0);

struct stat st;
assert(stat(".", ) == 0);
printf("st_mtim.tv_sec = %lld, st_mtim.tv_nsec = %lu\n",
   (long long) st.st_mtim.tv_sec,
   (unsigned long) st.st_mtim.tv_nsec);

struct statx stx;
assert(syscall(__NR_statx, AT_FDCWD, ".", 0, 0, ) == 0);
printf("stx_mtime.tv_sec = %lld, stx_mtime.tv_nsec = %lu\n",
   (long long) stx.stx_mtime.tv_sec,
   (unsigned long) stx.stx_mtime.tv_nsec);

return 0;
}

It expectedly prints:
st_mtim.tv_sec = -2, st_mtim.tv_nsec = 42
stx_mtime.tv_sec = -2, stx_mtime.tv_nsec = 42

The more generic comment asserting that the value of struct
statx_timestamp.tv_nsec might be negative is confusing to say the least.

It contradicts both the struct stat.st_[acm]time_nsec tradition and
struct timespec.tv_nsec requirements in utimensat syscall.
If statx syscall ever returns a stx_[acm]time containing a negative
tv_nsec that cannot be passed unmodified to utimensat syscall,
it will cause an immense confusion.

Fix this source of confusion by changing the type of struct
statx_timestamp.tv_nsec from __s32 to __u32.

Fixes: a528d35e8bfc ("statx: Add a system call to make enhanced file info 
available")
Signed-off-by: Dmitry V. Levin 
---
v1: fix misleading comments
v2: change the type from __s32 to __u32
---
 include/uapi/linux/stat.h | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h
index d538897..17b1030 100644
--- a/include/uapi/linux/stat.h
+++ b/include/uapi/linux/stat.h
@@ -48,17 +48,13 @@
  * tv_sec holds the number of seconds before (negative) or after (positive)
  * 00:00:00 1st January 1970 UTC.
  *
- * tv_nsec holds a number of nanoseconds before (0..-999,999,999 if tv_sec is
- * negative) or after (0..999,999,999 if tv_sec is positive) the tv_sec time.
- *
- * Note that if both tv_sec and tv_nsec are non-zero, then the two values must
- * either be both positive or both negative.
+ * tv_nsec holds a number of nanoseconds (0..999,999,999) after the tv_sec 
time.
  *
  * __reserved is held in case we need a yet finer resolution.
  */
 struct statx_timestamp {
__s64   tv_sec;
-   __s32   tv_nsec;
+   __u32   tv_nsec;
__s32   __reserved;
 };
 
-- 
ldv


Re: [PATCH] uapi: fix linux/nfsd/cld.h userspace compilation errors

2017-03-09 Thread Dmitry V. Levin
On Thu, Mar 09, 2017 at 04:00:51PM -0500, J. Bruce Fields wrote:
> Why aren't the unitX_t types OK here?

unitX_t types are not OK here because no UAPI header defines them,
include/uapi/linux/types.h defines only their __uX/__sX analogues.

For this reason most of UAPI headers use types provided by
, see e.g. include/uapi/linux/nfsd/nfsfh.h

There are few exceptions to this rule when headers are made portable
between linux and other operating systems.

> Anyway, assuming this is right I'll apply for 4.12.  (I'm assuming it's
> not urgent since this file's always been this way.)

This should be safe to apply for 4.11 as well, but it's surely not urgent.

> --b.
> 
> On Wed, Mar 01, 2017 at 03:12:03AM +0300, Dmitry V. Levin wrote:
> > Include  and consistently use types it provides
> > to fix the following linux/nfsd/cld.h userspace compilation errors:
> > 
> > /usr/include/linux/nfsd/cld.h:40:2: error: unknown type name 'uint16_t'
> >   uint16_t cn_len;/* length of cm_id */
> > /usr/include/linux/nfsd/cld.h:46:2: error: unknown type name 'uint8_t'
> >   uint8_t  cm_vers;  /* upcall version */
> > /usr/include/linux/nfsd/cld.h:47:2: error: unknown type name 'uint8_t'
> >   uint8_t  cm_cmd;   /* upcall command */
> > /usr/include/linux/nfsd/cld.h:48:2: error: unknown type name 'int16_t'
> >   int16_t  cm_status;  /* return code */
> > /usr/include/linux/nfsd/cld.h:49:2: error: unknown type name 'uint32_t'
> >   uint32_t cm_xid;   /* transaction id */
> > /usr/include/linux/nfsd/cld.h:51:3: error: unknown type name 'int64_t'
> >int64_t  cm_gracetime; /* grace period start time */
> > 
> > Signed-off-by: Dmitry V. Levin 
> > ---
> >  include/uapi/linux/nfsd/cld.h | 14 --
> >  1 file changed, 8 insertions(+), 6 deletions(-)
> > 
> > diff --git a/include/uapi/linux/nfsd/cld.h b/include/uapi/linux/nfsd/cld.h
> > index f14a9ab..ec26027 100644
> > --- a/include/uapi/linux/nfsd/cld.h
> > +++ b/include/uapi/linux/nfsd/cld.h
> > @@ -22,6 +22,8 @@
> >  #ifndef _NFSD_CLD_H
> >  #define _NFSD_CLD_H
> >  
> > +#include 
> > +
> >  /* latest upcall version available */
> >  #define CLD_UPCALL_VERSION 1
> >  
> > @@ -37,18 +39,18 @@ enum cld_command {
> >  
> >  /* representation of long-form NFSv4 client ID */
> >  struct cld_name {
> > -   uint16_tcn_len; /* length of cm_id */
> > +   __u16   cn_len; /* length of cm_id */
> > unsigned char   cn_id[NFS4_OPAQUE_LIMIT];   /* client-provided */
> >  } __attribute__((packed));
> >  
> >  /* message struct for communication with userspace */
> >  struct cld_msg {
> > -   uint8_t cm_vers;/* upcall version */
> > -   uint8_t cm_cmd; /* upcall command */
> > -   int16_t cm_status;  /* return code */
> > -   uint32_tcm_xid; /* transaction id */
> > +   __u8cm_vers;/* upcall version */
> > +   __u8cm_cmd; /* upcall command */
> > +   __s16   cm_status;  /* return code */
> > +   __u32   cm_xid; /* transaction id */
> > union {
> > -   int64_t cm_gracetime;   /* grace period start time */
> > +   __s64   cm_gracetime;   /* grace period start time */
> > struct cld_name cm_name;
> > } __attribute__((packed)) cm_u;
> >  } __attribute__((packed));
> > -- 
> > ldv

-- 
ldv


pgpeVo3aw5cWv.pgp
Description: PGP signature


Re: Compat 32-bit syscall entry from 64-bit task!?

2017-03-13 Thread Dmitry V. Levin
On Wed, Mar 08, 2017 at 08:39:55PM -0800, Andrew Lutomirski wrote:
> On Wed, Mar 8, 2017 at 3:41 PM, Dmitry V. Levin wrote:
[...]
> > Is there any progress with this (or any alternative) solution?
> >
> > I see the kernel side has changed a bit, and the strace part
> > is in a better shape than 5 years ago (although I'm biased of course),
> > but I don't see any kernel interface that would allow strace to reliably
> > recognize this 0x80 case.
> 
> I am strongly opposed to fudging registers to half-arsedly slightly
> improve the epicly crappy ptrace(2) interface for syscalls.
> 
> To fix this right, please just add PTRACE_GET_SYSCALL_INFO or similar
> to, in one shot, read out all the syscall details.  This means: arch,
> no, arg0..arg5, and *whether it's entry or exit*.  I propose returning
> this structure:
> 
> struct ptrace_syscall_info {
>   u8 op;  /* 0 for entry, 1 for exit */
>   u8 pad0;
>   u16 pad1;
>   u32 pad2;
>   union {
> struct seccomp_data syscall_entry;
> s64 syscall_exit_retval;
>   };
> };
> 
> because struct seccomp_data already gets this right.  There's plenty
> of opportunity to fine-tune this.  Now it works on all architectures.

Unfortunately, the API is missing.

Unlike syscall_get_nr(), syscall_get_arch() works with the current task
only so there is no API to get the arch identifier for the given task
that would work on all architectures.


-- 
ldv


pgpkmPAKkKJMR.pgp
Description: PGP signature


[PATCH v3 2/2] x86/uapi: fix asm/signal.h userspace compilation error

2017-03-02 Thread Dmitry V. Levin
Replace size_t with __kernel_uapi_size_t to fix the following
asm/signal.h userspace compilation error:

/usr/include/asm/signal.h:126:2: error: unknown type name 'size_t'
  size_t ss_size;

Signed-off-by: Dmitry V. Levin 
Link: http://lkml.kernel.org/r/20170302001853.ga27...@altlinux.org
---
 arch/x86/include/uapi/asm/signal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/uapi/asm/signal.h 
b/arch/x86/include/uapi/asm/signal.h
index 8264f47..c8b2c95 100644
--- a/arch/x86/include/uapi/asm/signal.h
+++ b/arch/x86/include/uapi/asm/signal.h
@@ -127,7 +127,7 @@ struct sigaction {
 typedef struct sigaltstack {
void __user *ss_sp;
int ss_flags;
-   size_t ss_size;
+   __kernel_uapi_size_t ss_size;
 } stack_t;
 
 #endif /* __ASSEMBLY__ */
-- 
ldv


[PATCH 1/2] uapi: introduce __kernel_uapi_size_t

2017-03-02 Thread Dmitry V. Levin
__kernel_uapi_size_t is a pure UAPI type, in defined(__KERNEL__) code
it's always the same as __kernel_size_t.

It's also the same as __kernel_size_t on all architectures except x32
where sizeof(size_t) < sizeof(__kernel_size_t).

__kernel_uapi_size_t can be used as a size_t replacement in UAPI
headers, e.g. in cases when size_t might differ from __kernel_size_t.

Signed-off-by: Dmitry V. Levin 
---
 include/uapi/asm-generic/posix_types.h  | 10 ++
 arch/x86/include/uapi/asm/posix_types_x32.h |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/include/uapi/asm-generic/posix_types.h 
b/include/uapi/asm-generic/posix_types.h
index fe74fcc..e93c324 100644
--- a/include/uapi/asm-generic/posix_types.h
+++ b/include/uapi/asm-generic/posix_types.h
@@ -74,6 +74,16 @@ typedef __kernel_long_t  __kernel_ptrdiff_t;
 #endif
 #endif
 
+/*
+ * __kernel_uapi_size_t is a pure UAPI type, in defined(__KERNEL__) code
+ * it's always the same as __kernel_size_t.
+ * __kernel_uapi_size_t can be used as a size_t replacement in UAPI headers,
+ * e.g. in cases when size_t might differ from __kernel_size_t.
+ */
+#ifndef __kernel_uapi_size_t
+typedef __kernel_size_t __kernel_uapi_size_t;
+#endif
+
 #ifndef __kernel_fsid_t
 typedef struct {
int val[2];
diff --git a/arch/x86/include/uapi/asm/posix_types_x32.h 
b/arch/x86/include/uapi/asm/posix_types_x32.h
index 85f9bda..0e36e67 100644
--- a/arch/x86/include/uapi/asm/posix_types_x32.h
+++ b/arch/x86/include/uapi/asm/posix_types_x32.h
@@ -14,6 +14,9 @@ typedef long long __kernel_long_t;
 typedef unsigned long long __kernel_ulong_t;
 #define __kernel_long_t __kernel_long_t
 
+typedef unsigned int __kernel_uapi_size_t;
+#define __kernel_uapi_size_t __kernel_uapi_size_t
+
 #include 
 
 #endif /* _ASM_X86_POSIX_TYPES_X32_H */
-- 
ldv


Re: [PATCH] x86: use compat version for preadv2 and pwritev2

2016-05-12 Thread Dmitry V. Levin
On Thu, May 12, 2016 at 09:30:37AM +0200, Christoph Hellwig wrote:
> On Wed, May 11, 2016 at 11:48:17AM +0300, Dmitry V. Levin wrote:
> > Similar to preadv and pwritev, preadv2 and pwritev2 need compat entries
> > in the 32-bit syscall table.
> > 
> > This bug was found by strace test suite.
> 
> Looks fine, thanks.

BTW, x32 hasn't got entries for preadv2/pwritev2 at all.
Not a problem, just a reminder.


-- 
ldv


[PATCH] x86: use compat version for preadv2 and pwritev2

2016-05-11 Thread Dmitry V. Levin
Similar to preadv and pwritev, preadv2 and pwritev2 need compat entries
in the 32-bit syscall table.

This bug was found by strace test suite.

Fixes: 4babf2c5efb7 ("x86: wire up preadv2 and pwritev2")
Signed-off-by: Dmitry V. Levin 
---
 arch/x86/entry/syscalls/syscall_32.tbl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl 
b/arch/x86/entry/syscalls/syscall_32.tbl
index b30dd81..4cddd17 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -384,5 +384,5 @@
 375i386membarrier  sys_membarrier
 376i386mlock2  sys_mlock2
 377i386copy_file_range sys_copy_file_range
-378i386preadv2 sys_preadv2
-379i386pwritev2sys_pwritev2
+378i386preadv2 sys_preadv2 
compat_sys_preadv2
+379i386pwritev2sys_pwritev2
compat_sys_pwritev2
-- 
ldv


Re: [PATCH] x86: use compat version for preadv2 and pwritev2

2016-05-11 Thread Dmitry V. Levin
On Wed, May 11, 2016 at 12:14:11PM +0200, Thomas Gleixner wrote:
> On Wed, 11 May 2016, Dmitry V. Levin wrote:
> > Similar to preadv and pwritev, preadv2 and pwritev2 need compat entries
> > in the 32-bit syscall table.
> 
> So this is 2016 and we added a syscalls which require compat support. What's
> wrong here?

I'm not sure I understand your question, it looks to me as "why do we add
syscalls that require compat support".  If that's what you are asking,
I have no idea, I'm a strace man.


-- 
ldv


[PATCH] parisc: fix a bug when syscall number of tracee is __NR_Linux_syscalls

2016-04-26 Thread Dmitry V. Levin
Do not load one entry beyond the end of the syscall table when the
syscall number of a traced process equals to __NR_Linux_syscalls.
Similar bug with regular processes was fixed by commit 3bb457af4fa8
("[PARISC] Fix bug when syscall nr is __NR_Linux_syscalls").

This bug was found by strace test suite.

Cc: sta...@vger.kernel.org
Signed-off-by: Dmitry V. Levin 
---
 arch/parisc/kernel/syscall.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/parisc/kernel/syscall.S b/arch/parisc/kernel/syscall.S
index c976ebf..57b4836 100644
--- a/arch/parisc/kernel/syscall.S
+++ b/arch/parisc/kernel/syscall.S
@@ -344,7 +344,7 @@ tracesys_next:
 #endif
 
cmpib,COND(=),n -1,%r20,tracesys_exit /* seccomp may have returned -1 */
-   comiclr,>>= __NR_Linux_syscalls, %r20, %r0
+   comiclr,>>  __NR_Linux_syscalls, %r20, %r0
b,n .Ltracesys_nosys
 
LDREGX  %r20(%r19), %r19
-- 
ldv


Re: [PATCH] parisc: fix a bug when syscall number of tracee is __NR_Linux_syscalls

2016-04-26 Thread Dmitry V. Levin
On Tue, Apr 26, 2016 at 10:45:11PM -0400, Mike Frysinger wrote:
> On 27 Apr 2016 04:56, Dmitry V. Levin wrote:
> > Do not load one entry beyond the end of the syscall table when the
> > syscall number of a traced process equals to __NR_Linux_syscalls.
> > Similar bug with regular processes was fixed by commit 3bb457af4fa8
> > ("[PARISC] Fix bug when syscall nr is __NR_Linux_syscalls").
> > 
> > This bug was found by strace test suite.
> > 
> > Cc: sta...@vger.kernel.org
> > Signed-off-by: Dmitry V. Levin 
> > ---
> >  arch/parisc/kernel/syscall.S | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/parisc/kernel/syscall.S b/arch/parisc/kernel/syscall.S
> > index c976ebf..57b4836 100644
> > --- a/arch/parisc/kernel/syscall.S
> > +++ b/arch/parisc/kernel/syscall.S
> > @@ -344,7 +344,7 @@ tracesys_next:
> >  #endif
> >  
> > cmpib,COND(=),n -1,%r20,tracesys_exit /* seccomp may have returned -1 */
> > -   comiclr,>>= __NR_Linux_syscalls, %r20, %r0
> > +   comiclr,>>  __NR_Linux_syscalls, %r20, %r0
> > b,n .Ltracesys_nosys
> >  
> > LDREGX  %r20(%r19), %r19
> 
> i've deployd your fix to hake, so feel free to give the tests another
> run to try and crash the box :).

With this fix the box no longer crashes.


-- 
ldv


pgpdfCtDW94Mc.pgp
Description: PGP signature


[PATCH] x86/signal: fix restart_syscall number for x32 tasks

2015-11-30 Thread Dmitry V. Levin
When restarting a syscall with regs->ax == -ERESTART_RESTARTBLOCK,
regs->ax is assigned to a restart_syscall number.  For x32 tasks,
this syscall number must have __X32_SYSCALL_BIT set, otherwise it
will be an x86_64 syscall number instead of a valid x32 syscall number.

Reported-by: strace/tests/restart_syscall.test
Reported-and-tested-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
Cc: sta...@vger.kernel.org
---
 arch/x86/kernel/signal.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b7ffb7c..cb6282c 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -690,12 +690,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
signal_setup_done(failed, ksig, stepping);
 }
 
-#ifdef CONFIG_X86_32
-#define NR_restart_syscall __NR_restart_syscall
-#else /* !CONFIG_X86_32 */
-#define NR_restart_syscall \
-   test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : 
__NR_restart_syscall
-#endif /* CONFIG_X86_32 */
+static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
+{
+#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+   return __NR_restart_syscall;
+#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
+   return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
+   __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
+#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
+}
 
 /*
  * Note that 'init' is a special process: it doesn't get signals it doesn't
@@ -724,7 +727,7 @@ void do_signal(struct pt_regs *regs)
break;
 
case -ERESTART_RESTARTBLOCK:
-   regs->ax = NR_restart_syscall;
+   regs->ax = get_nr_restart_syscall(regs);
regs->ip -= 2;
break;
}
-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND PATCH 4/4] vfs: show_vfsstat: remove redundant initialization and check of error code

2015-12-02 Thread Dmitry V. Levin
Date: Wed, 18 Nov 2015 21:09:45 +

As err variable is now always checked right after each assignment, its
initialization is redundant and could be safely removed.  For the same
reason, the last check of err is also redundant and could be removed as
well.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 7a6b2f3..3f1190d 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -193,7 +193,7 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount 
*mnt)
struct mount *r = real_mount(mnt);
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
struct super_block *sb = mnt_path.dentry->d_sb;
-   int err = 0;
+   int err;
 
/* device */
if (sb->s_op->show_devname) {
@@ -224,8 +224,7 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount 
*mnt)
/* optional statistics */
if (sb->s_op->show_stats) {
seq_putc(m, ' ');
-   if (!err)
-   err = sb->s_op->show_stats(m, mnt_path.dentry);
+   err = sb->s_op->show_stats(m, mnt_path.dentry);
}
 
seq_putc(m, '\n');

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND PATCH 3/4] vfs: show_mountinfo: cleanup error code checks

2015-12-02 Thread Dmitry V. Levin
Wed, 18 Nov 2015 21:08:33 +

Check err variable right after each assignment.  This change makes
initialization of err redundant, so remove the initialization.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index cbc9c27..7a6b2f3 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -131,16 +131,17 @@ static int show_mountinfo(struct seq_file *m, struct 
vfsmount *mnt)
struct mount *r = real_mount(mnt);
struct super_block *sb = mnt->mnt_sb;
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
-   int err = 0;
+   int err;
 
seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
   MAJOR(sb->s_dev), MINOR(sb->s_dev));
-   if (sb->s_op->show_path)
+   if (sb->s_op->show_path) {
err = sb->s_op->show_path(m, mnt->mnt_root);
-   else
+   if (err)
+   goto out;
+   } else {
seq_dentry(m, mnt->mnt_root, " \t\n\\");
-   if (err)
-   goto out;
+   }
seq_putc(m, ' ');
 
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
@@ -168,12 +169,13 @@ static int show_mountinfo(struct seq_file *m, struct 
vfsmount *mnt)
seq_puts(m, " - ");
show_type(m, sb);
seq_putc(m, ' ');
-   if (sb->s_op->show_devname)
+   if (sb->s_op->show_devname) {
err = sb->s_op->show_devname(m, mnt->mnt_root);
-   else
+   if (err)
+   goto out;
+   } else {
mangle(m, r->mnt_devname ? r->mnt_devname : "none");
-   if (err)
-   goto out;
+   }
seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
err = show_sb_opts(m, sb);
if (err)

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND PATCH 2/4] vfs: show_vfsmnt: remove redundant initialization of error code

2015-12-02 Thread Dmitry V. Levin
Date: Wed, 18 Nov 2015 21:07:10 +

As err variable is now always checked right after the first assignment,
its initialization is redundant and could be safely removed.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 876459559..cbc9c27 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -95,9 +95,9 @@ static int show_vfsmnt(struct seq_file *m, struct vfsmount 
*mnt)
 {
struct proc_mounts *p = m->private;
struct mount *r = real_mount(mnt);
-   int err = 0;
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
struct super_block *sb = mnt_path.dentry->d_sb;
+   int err;
 
if (sb->s_op->show_devname) {
err = sb->s_op->show_devname(m, mnt_path.dentry);

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND v2 PATCH 1/4] vfs: show_vfsstat: do not ignore errors from show_devname method

2015-12-02 Thread Dmitry V. Levin
Date: Thu, 19 Mar 2015 11:10:54 +

Explicitly check show_devname method return code and bail out in case
of an error.  This fixes regression introduced by commit 9d4d65748a5c.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 8ebd9a3..876459559 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -197,17 +197,19 @@ static int show_vfsstat(struct seq_file *m, struct 
vfsmount *mnt)
if (sb->s_op->show_devname) {
seq_puts(m, "device ");
err = sb->s_op->show_devname(m, mnt_path.dentry);
+   if (err)
+   goto out;
} else {
if (r->mnt_devname) {
seq_puts(m, "device ");
mangle(m, r->mnt_devname);
} else
seq_puts(m, "no device");
}
 
/* mount point */
seq_puts(m, " mounted on ");
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
err = seq_path_root(m, _path, >root, " \t\n\\");
if (err)
goto out;

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 8/8] Use __kernel_long_t in struct mq_attr

2015-11-23 Thread Dmitry V. Levin
On Fri, Dec 27, 2013 at 02:14:24PM -0800, H.J. Lu wrote:
> Both x32 and x86-64 use the same struct mq_attr for system calls.  But
> x32 long is 32-bit. This patch replaces long with __kernel_long_t in
> struct mq_attr.
> 
> Signed-off-by: H.J. Lu 
> ---
>  include/uapi/linux/mqueue.h | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/include/uapi/linux/mqueue.h b/include/uapi/linux/mqueue.h
> index 8b5a796..d0a2b8e 100644
> --- a/include/uapi/linux/mqueue.h
> +++ b/include/uapi/linux/mqueue.h
> @@ -23,11 +23,11 @@
>  #define MQ_BYTES_MAX 819200
>  
>  struct mq_attr {
> - longmq_flags;   /* message queue flags  */
> - longmq_maxmsg;  /* maximum number of messages   */
> - longmq_msgsize; /* maximum message size */
> - longmq_curmsgs; /* number of messages currently queued  */
> - long__reserved[4];  /* ignored for input, zeroed for output */
> + __kernel_long_t mq_flags;   /* message queue flags  
> */
> + __kernel_long_t mq_maxmsg;  /* maximum number of messages   
> */
> + __kernel_long_t mq_msgsize; /* maximum message size 
> */
> + __kernel_long_t mq_curmsgs; /* number of messages currently queued  
> */
> + __kernel_long_t __reserved[4];  /* ignored for input, zeroed for output 
> */
>  };
>  
>  /*

This breaks userspace, please #include 
before using __kernel_long_t.


-- 
ldv


pgpnSs0iZClaI.pgp
Description: PGP signature


[PATCH] sh64: fix __NR_fgetxattr

2015-12-08 Thread Dmitry V. Levin
According to arch/sh/kernel/syscalls_64.S and common sense,
__NR_fgetxattr has to be defined to 259, but it doesn't.
Instead, it's defined to 269, which is of course used
by another syscall, __NR_sched_setaffinity in this case.

This bug was found by strace test suite.

Signed-off-by: Dmitry V. Levin 
Cc: sta...@vger.kernel.org
---
 arch/sh/include/uapi/asm/unistd_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sh/include/uapi/asm/unistd_64.h 
b/arch/sh/include/uapi/asm/unistd_64.h
index e6820c8..47ebd5b 100644
--- a/arch/sh/include/uapi/asm/unistd_64.h
+++ b/arch/sh/include/uapi/asm/unistd_64.h
@@ -278,7 +278,7 @@
 #define __NR_fsetxattr 256
 #define __NR_getxattr  257
 #define __NR_lgetxattr 258
-#define __NR_fgetxattr 269
+#define __NR_fgetxattr 259
 #define __NR_listxattr 260
 #define __NR_llistxattr261
 #define __NR_flistxattr262
-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RESEND PATCH] vfs: show_vfsstat: do not ignore errors from show_devname method

2015-11-18 Thread Dmitry V. Levin
Date: Thu, 19 Mar 2015 11:10:54 +

Explicitly check show_devname method return code and bail out in case
of an error.  This fixes regression introduced by commit 9d4d65748a5c.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 8ebd9a3..876459559 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -197,17 +197,19 @@ static int show_vfsstat(struct seq_file *m, struct 
vfsmount *mnt)
if (sb->s_op->show_devname) {
seq_puts(m, "device ");
err = sb->s_op->show_devname(m, mnt_path.dentry);
+   if (err)
+   goto out;
} else {
if (r->mnt_devname) {
seq_puts(m, "device ");
mangle(m, r->mnt_devname);
} else
seq_puts(m, "no device");
}
 
/* mount point */
seq_puts(m, " mounted on ");
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
err = seq_path_root(m, _path, >root, " \t\n\\");
if (err)
goto out;

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] vfs: show_vfsmnt: remove redundant initialization of error code

2015-11-18 Thread Dmitry V. Levin
As err variable is now always checked right after the first assignment,
its initialization is redundant and could be safely removed.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 876459559..cbc9c27 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -95,9 +95,9 @@ static int show_vfsmnt(struct seq_file *m, struct vfsmount 
*mnt)
 {
struct proc_mounts *p = m->private;
struct mount *r = real_mount(mnt);
-   int err = 0;
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
struct super_block *sb = mnt_path.dentry->d_sb;
+   int err;
 
if (sb->s_op->show_devname) {
err = sb->s_op->show_devname(m, mnt_path.dentry);

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] vfs: show_mountinfo: cleanup error code checks

2015-11-18 Thread Dmitry V. Levin
Check err variable right after each assignment.  This change makes
initialization of err redundant, so remove the initialization.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index cbc9c27..7a6b2f3 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -131,16 +131,17 @@ static int show_mountinfo(struct seq_file *m, struct 
vfsmount *mnt)
struct mount *r = real_mount(mnt);
struct super_block *sb = mnt->mnt_sb;
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
-   int err = 0;
+   int err;
 
seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
   MAJOR(sb->s_dev), MINOR(sb->s_dev));
-   if (sb->s_op->show_path)
+   if (sb->s_op->show_path) {
err = sb->s_op->show_path(m, mnt->mnt_root);
-   else
+   if (err)
+   goto out;
+   } else {
seq_dentry(m, mnt->mnt_root, " \t\n\\");
-   if (err)
-   goto out;
+   }
seq_putc(m, ' ');
 
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
@@ -168,12 +169,13 @@ static int show_mountinfo(struct seq_file *m, struct 
vfsmount *mnt)
seq_puts(m, " - ");
show_type(m, sb);
seq_putc(m, ' ');
-   if (sb->s_op->show_devname)
+   if (sb->s_op->show_devname) {
err = sb->s_op->show_devname(m, mnt->mnt_root);
-   else
+   if (err)
+   goto out;
+   } else {
mangle(m, r->mnt_devname ? r->mnt_devname : "none");
-   if (err)
-   goto out;
+   }
seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
err = show_sb_opts(m, sb);
if (err)

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] vfs: show_vfsstat: remove redundant initialization and check of error code

2015-11-18 Thread Dmitry V. Levin
As err variable is now always checked right after each assignment, its
initialization is redundant and could be safely removed.  For the same
reason, the last check of err is also redundant and could be removed as
well.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 7a6b2f3..3f1190d 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -193,7 +193,7 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount 
*mnt)
struct mount *r = real_mount(mnt);
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
struct super_block *sb = mnt_path.dentry->d_sb;
-   int err = 0;
+   int err;
 
/* device */
if (sb->s_op->show_devname) {
@@ -224,8 +224,7 @@ static int show_vfsstat(struct seq_file *m, struct vfsmount 
*mnt)
/* optional statistics */
if (sb->s_op->show_stats) {
seq_putc(m, ' ');
-   if (!err)
-   err = sb->s_op->show_stats(m, mnt_path.dentry);
+   err = sb->s_op->show_stats(m, mnt_path.dentry);
}
 
seq_putc(m, '\n');

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] unix_diag: fix incorrect sign extension in unix_lookup_by_ino

2016-02-18 Thread Dmitry V. Levin
The value passed by unix_diag_get_exact to unix_lookup_by_ino has type
__u32, but unix_lookup_by_ino's argument ino has type int, which is not
a problem yet.
However, when ino is compared with sock_i_ino return value of type
unsigned long, ino is sign extended to signed long, and this results
to incorrect comparison on 64-bit architectures for inode numbers
greater than INT_MAX.

This bug was found by strace test suite.

Signed-off-by: Dmitry V. Levin 
Cc: 
---
 net/unix/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/unix/diag.c b/net/unix/diag.c
index c512f64..4d96797 100644
--- a/net/unix/diag.c
+++ b/net/unix/diag.c
@@ -220,23 +220,23 @@ done:
return skb->len;
 }
 
-static struct sock *unix_lookup_by_ino(int ino)
+static struct sock *unix_lookup_by_ino(unsigned int ino)
 {
int i;
struct sock *sk;
 
spin_lock(_table_lock);
for (i = 0; i < ARRAY_SIZE(unix_socket_table); i++) {
sk_for_each(sk, _socket_table[i])
if (ino == sock_i_ino(sk)) {
sock_hold(sk);
spin_unlock(_table_lock);
 
return sk;
}
}
 
spin_unlock(_table_lock);
return NULL;
 }
 
-- 
ldv


[RESEND v3 PATCH] vfs: show_vfsstat: do not ignore errors from show_devname method

2016-02-18 Thread Dmitry V. Levin
Date: Thu, 19 Mar 2015 11:10:54 +

Explicitly check show_devname method return code and bail out in case
of an error.  This fixes regression introduced by commit 9d4d65748a5c.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 2256e7e..3f1190d 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -190,26 +190,28 @@ out:
 static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt)
 {
struct proc_mounts *p = m->private;
struct mount *r = real_mount(mnt);
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
struct super_block *sb = mnt_path.dentry->d_sb;
int err;
 
/* device */
if (sb->s_op->show_devname) {
seq_puts(m, "device ");
err = sb->s_op->show_devname(m, mnt_path.dentry);
+   if (err)
+   goto out;
} else {
if (r->mnt_devname) {
seq_puts(m, "device ");
mangle(m, r->mnt_devname);
} else
seq_puts(m, "no device");
}
 
/* mount point */
seq_puts(m, " mounted on ");
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
err = seq_path_root(m, _path, >root, " \t\n\\");
if (err)
goto out;
-- 
ldv


[RESEND v4 PATCH] vfs: show_vfsstat: do not ignore errors from show_devname method

2016-03-20 Thread Dmitry V. Levin
Date: Thu, 19 Mar 2015 11:10:54 +

Explicitly check show_devname method return code and bail out in case
of an error.  This fixes regression introduced by commit 9d4d65748a5c.

Signed-off-by: Dmitry V. Levin 
---
 fs/proc_namespace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 2256e7e..3f1190d 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -190,26 +190,28 @@ out:
 static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt)
 {
struct proc_mounts *p = m->private;
struct mount *r = real_mount(mnt);
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
struct super_block *sb = mnt_path.dentry->d_sb;
int err;
 
/* device */
if (sb->s_op->show_devname) {
seq_puts(m, "device ");
err = sb->s_op->show_devname(m, mnt_path.dentry);
+   if (err)
+   goto out;
} else {
if (r->mnt_devname) {
seq_puts(m, "device ");
mangle(m, r->mnt_devname);
} else
seq_puts(m, "no device");
}
 
/* mount point */
seq_puts(m, " mounted on ");
/* mountpoints outside of chroot jail will give SEQ_SKIP on this */
err = seq_path_root(m, _path, >root, " \t\n\\");
if (err)
goto out;
-- 
ldv


[PATCH] uapi: use __u64 instead of u64

2016-05-30 Thread Dmitry V. Levin
This bug was found by strace test suite.

Fixes: 6b526ed70cf1 ("btrfs: introduce device delete by devid")
Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/btrfs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 23c6960..2bdd1e3 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -118,7 +118,7 @@ struct btrfs_ioctl_vol_args_v2 {
};
union {
char name[BTRFS_SUBVOL_NAME_MAX + 1];
-   u64 devid;
+   __u64 devid;
};
 };
 
-- 
ldv


[PATCH] x86/signal: Cleanup get_nr_restart_syscall

2015-12-18 Thread Dmitry V. Levin
Check for TS_COMPAT instead of TIF_IA32 to distinguish ia32 tasks
from 64-bit tasks.
Check for __X32_SYSCALL_BIT only if CONFIG_X86_X32_ABI is defined.

Signed-off-by: Dmitry V. Levin 
Cc: Elvira Khabirova 
Cc: Andy Lutomirski 
---
 arch/x86/kernel/signal.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index cb6282c..ff7dedc 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -692,12 +692,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 
 static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
 {
-#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+#ifdef CONFIG_X86_64
+   if (is_ia32_task())
+   return __NR_ia32_restart_syscall;
+# ifdef CONFIG_X86_X32_ABI
+   if (regs->orig_ax & __X32_SYSCALL_BIT)
+   return __NR_restart_syscall | __X32_SYSCALL_BIT;
+# endif
+#endif
return __NR_restart_syscall;
-#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
-   return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
-   __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
-#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
 }
 
 /*
-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] x86/signal: Cleanup get_nr_restart_syscall

2015-12-19 Thread Dmitry V. Levin
Check for TS_COMPAT instead of TIF_IA32 to distinguish ia32 tasks
from 64-bit tasks.
Check for __X32_SYSCALL_BIT iff CONFIG_X86_X32_ABI is defined.

Signed-off-by: Dmitry V. Levin 
Cc: Elvira Khabirova 
Cc: Andy Lutomirski 
---
 v2: reintroduced __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT)

 arch/x86/kernel/signal.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index cb6282c..c07ff5d 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -692,12 +692,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 
 static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
 {
-#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+#ifdef CONFIG_X86_64
+   if (is_ia32_task())
+   return __NR_ia32_restart_syscall;
+#endif
+#ifdef CONFIG_X86_X32_ABI
+   return __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
+#else
return __NR_restart_syscall;
-#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
-   return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
-   __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
-#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
+#endif
 }
 
 /*
-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] sparc64: fix incorrect sign extension in sys_sparc64_personality

2015-12-26 Thread Dmitry V. Levin
The value returned by sys_personality has type "long int".
It is saved to a variable of type "int", which is not a problem
yet because the type of task_struct->pesonality is "unsigned int".
The problem is the sign extension from "int" to "long int"
that happens on return from sys_sparc64_personality.

For example, a userspace call personality((unsigned) -EINVAL) will
result to any subsequent personality call, including absolutely
harmless read-only personality(0x) call, failing with
errno set to EINVAL.

Signed-off-by: Dmitry V. Levin 
Cc: 
---
 arch/sparc/kernel/sys_sparc_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 30e7ddb..c690c8e 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -413,15 +413,15 @@ out:
 
 SYSCALL_DEFINE1(sparc64_personality, unsigned long, personality)
 {
-   int ret;
+   long ret;
 
if (personality(current->personality) == PER_LINUX32 &&
personality(personality) == PER_LINUX)
personality |= PER_LINUX32;
ret = sys_personality(personality);
if (personality(ret) == PER_LINUX32)
ret &= ~PER_LINUX32;
 
return ret;
 }

-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] x86/signal: fix restart_syscall number for x32 tasks

2015-12-12 Thread Dmitry V. Levin
On Mon, Dec 07, 2015 at 03:22:06PM -0800, Andy Lutomirski wrote:
> [not real reply because I'm using a bad internet connection right now
> and I'm not set up with my usual Gmane reply hack right now]
> 
> The new code is (whitespace-damaged):
> 
> static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
> {
> #if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
>  return __NR_restart_syscall;
> #else /* !CONFIG_X86_32 && CONFIG_X86_64 */
>  return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
>  __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
> #endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
> }
> 
> This is IMO awful.  This use of TIF_IA32 is wrong, and this is
> otherwise gross.  Can we do it for real:
> 
> if (is_ia32_task())
>   return __NR_ia32_restart_syscall;
> else
>   return __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
> /* preserve x32 bit */
> 
> I'd send the patch myself, but you apparently have a good test case
> for this, and I don't.

Unfortunately, this won't compile on CONFIG_X86_32 because
__NR_ia32_restart_syscall is defined for CONFIG_X86_64 only.

Something like this should work:

static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
{
#ifdef CONFIG_X86_64
if (is_ia32_task())
return __NR_ia32_restart_syscall;
# ifdef CONFIG_X86_X32_ABI
if (regs->orig_ax & __X32_SYSCALL_BIT)
return __NR_restart_syscall | __X32_SYSCALL_BIT;
# endif
#endif
return __NR_restart_syscall;
}

I don't see any way to avoid ifdefs here, sorry.


-- 
ldv
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: Linux include/uapi/linux/libc-compat.h and Musl include/netinet/in.h incompatibility for __UAPI_DEF_IN6_ADDR_ALT

2021-03-29 Thread Dmitry V. Levin
Hi,

On Tue, Mar 30, 2021 at 12:30:52PM +1300, Chris Packham wrote:
> Hi,
> 
> I've come over from https://github.com/strace/strace/issues/177
> there's a bit of context there.
> 
> Crosstool-ng has hit a problem when building a recent enough version
> of strace in a configuration that uses musl libc.
> 
> The error is
> 
> [ALL  ]In file included from
> /home/x-tool/.build/arm-unknown-linux-musleabi/src/strace/bundled/linux/include/uapi/linux/in6.h:26,
> [ALL  ] from
> /home/x-tool/.build/arm-unknown-linux-musleabi/src/strace/bundled/linux/include/uapi/linux/if_bridge.h:19,
> [ALL  ] from
> /home/x-tool/.build/arm-unknown-linux-musleabi/src/strace/src/rtnl_mdb.c:16:
> [ERROR]
> /home/x-tool/.build/arm-unknown-linux-musleabi/src/strace/bundled/linux/include/uapi/linux/libc-compat.h:109:
> error: "__UAPI_DEF_IN6_ADDR_ALT" redefined [-Werror]
> [ALL  ]  109 | #define __UAPI_DEF_IN6_ADDR_ALT  1
> [ALL  ]  |
> [ALL  ]In file included from
> /home/x-tool/.build/arm-unknown-linux-musleabi/src/strace/src/rtnl_mdb.c:15:
> [ALL  ]
> /home/x-tool/x-tools/arm-unknown-linux-musleabi/arm-unknown-linux-musleabi/sysroot/usr/include/netinet/in.h:401:
> note: this is the location of the previous definition
> [ALL  ]  401 | #define __UAPI_DEF_IN6_ADDR_ALT 0
> [ALL  ]  |
> [ALL  ]cc1: all warnings being treated as errors
> [ERROR]make[4]: *** [Makefile:6660: libstrace_a-rtnl_mdb.o] Error 1
> [ALL  ]make[4]: Leaving directory
> '/home/x-tool/.build/arm-unknown-linux-musleabi/build/build-strace/src'
> [ERROR]make[3]: *** [Makefile:2404: all] Error 2
> [ALL  ]rm ioctlsort0.o ioctls_all0.h ioctlsort0
> [ALL  ]make[3]: Leaving directory
> '/home/x-tool/.build/arm-unknown-linux-musleabi/build/build-strace/src'
> [ERROR]make[2]: *** [Makefile:601: all-recursive] Error 1
> [ALL  ]make[2]: Leaving directory
> '/home/x-tool/.build/arm-unknown-linux-musleabi/build/build-strace'
> [ERROR]make[1]: *** [Makefile:506: all] Error 2
> [ALL  ]make[1]: Leaving directory
> '/home/x-tool/.build/arm-unknown-linux-musleabi/build/build-strace'
> 
> It appears that the bundled uapi headers definition of
> __UAPI_DEF_IN6_ADDR_ALT conflicts with the musl libc definition. It
> looks like libc-compat.h tries to co-exists with GNU libc but this
> isn't working for musl.

This essentially means that such basic things as
#include 
#include 
are broken in your setup.


-- 
ldv


Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign

2021-03-03 Thread Dmitry V. Levin
On Wed, Mar 03, 2021 at 03:30:19PM +0100, Oleg Nesterov wrote:
> On 03/02, Sergei Trofimovich wrote:
> >
> > > --- a/arch/ia64/include/asm/syscall.h
> > > +++ b/arch/ia64/include/asm/syscall.h
> > > @@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct 
> > > *task,
> > >  static inline long syscall_get_error(struct task_struct *task,
> > >struct pt_regs *regs)
> > >  {
> > > - return regs->r10 == -1 ? regs->r8:0;
> > > + return regs->r10 == -1 ? -regs->r8:0;
> > >  }
> > >
> > >  static inline long syscall_get_return_value(struct task_struct *task,
> > > --
> > > 2.30.1
> > >
> >
> > Andrew, would it be fine to pass it through misc tree?
> > Or should it go through Oleg as it's mostly about ptrace?
> 
> We usually route ptrace fixes via mm tree.
> 
> But this fix and another patch from you "ia64: fix 
> ia64_syscall_get_set_arguments()
> for break-based syscalls" look very much ia64 specific. I don't think it's 
> actually
> about ptrace, and I didn't even try to review these patches because I do not
> understand this low level ia64 code.
> 
> Can it be routed via ia64 tree? Add Tony and Fenghua...

Apparently [1], ia64 architecture is now orphaned, so we don't have this
option anymore.

[1] https://git.kernel.org/torvalds/c/96ec72a3425d1515b69b7f9dc34a4a6ce5862a37


-- 
ldv


Re: [PATCH] ia64: fix ptrace(PTRACE_SYSCALL_INFO_EXIT) sign

2021-03-03 Thread Dmitry V. Levin
On Sun, Feb 21, 2021 at 12:25:54AM +, Sergei Trofimovich wrote:
> In https://bugs.gentoo.org/769614 Dmitry noticed that
> `ptrace(PTRACE_GET_SYSCALL_INFO)` does not return error sign properly.
> 
> The bug is in mismatch between get/set errors:
> 
> static inline long syscall_get_error(struct task_struct *task,
>  struct pt_regs *regs)
> {
> return regs->r10 == -1 ? regs->r8:0;
> }
> 
> static inline long syscall_get_return_value(struct task_struct *task,
> struct pt_regs *regs)
> {
> return regs->r8;
> }
> 
> static inline void syscall_set_return_value(struct task_struct *task,
> struct pt_regs *regs,
> int error, long val)
> {
> if (error) {
> /* error < 0, but ia64 uses > 0 return value */
> regs->r8 = -error;
> regs->r10 = -1;
> } else {
> regs->r8 = val;
> regs->r10 = 0;
> }
> }
> 
> Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
> 
> CC: linux-i...@vger.kernel.org
> CC: linux-kernel@vger.kernel.org
> CC: Andrew Morton 
> Reported-by: Dmitry V. Levin 
> Bug: https://bugs.gentoo.org/769614
> Signed-off-by: Sergei Trofimovich 
> ---
>  arch/ia64/include/asm/syscall.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/ia64/include/asm/syscall.h b/arch/ia64/include/asm/syscall.h
> index 6c6f16e409a8..0d23c0049301 100644
> --- a/arch/ia64/include/asm/syscall.h
> +++ b/arch/ia64/include/asm/syscall.h
> @@ -32,7 +32,7 @@ static inline void syscall_rollback(struct task_struct 
> *task,
>  static inline long syscall_get_error(struct task_struct *task,
>struct pt_regs *regs)
>  {
> - return regs->r10 == -1 ? regs->r8:0;
> + return regs->r10 == -1 ? -regs->r8:0;
>  }
>  
>  static inline long syscall_get_return_value(struct task_struct *task,

Reviewed-by: Dmitry V. Levin 


-- 
ldv


Re: [PATCH] ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls

2021-03-03 Thread Dmitry V. Levin
On Sun, Feb 21, 2021 at 12:25:53AM +, Sergei Trofimovich wrote:
> In https://bugs.gentoo.org/769614 Dmitry noticed that
> `ptrace(PTRACE_GET_SYSCALL_INFO)` does not work for syscalls called
> via glibc's syscall() wrapper.
> 
> ia64 has two ways to call syscalls from userspace: via `break` and via
> `eps` instructions.
> 
> The difference is in stack layout:
> 
> 1. `eps` creates simple stack frame: no locals, in{0..7} == out{0..8}
> 2. `break` uses userspace stack frame: may be locals (glibc provides
>one), in{0..7} == out{0..8}.
> 
> Both work fine in syscall handling cde itself.
> 
> But `ptrace(PTRACE_GET_SYSCALL_INFO)` uses unwind mechanism to
> re-extract syscall arguments but it does not account for locals.
> 
> The change always skips locals registers. It should not change `eps`
> path as kernel's handler already enforces locals=0 and fixes `break`.
> 
> Tested on v5.10 on rx3600 machine (ia64 9040 CPU).
> 
> CC: Oleg Nesterov 
> CC: linux-i...@vger.kernel.org
> CC: linux-kernel@vger.kernel.org
> CC: Andrew Morton 
> Reported-by: Dmitry V. Levin 
> Bug: https://bugs.gentoo.org/769614
> Signed-off-by: Sergei Trofimovich 
> ---
>  arch/ia64/kernel/ptrace.c | 24 ++--
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
> index c3490ee2daa5..e14f5653393a 100644
> --- a/arch/ia64/kernel/ptrace.c
> +++ b/arch/ia64/kernel/ptrace.c
> @@ -2013,27 +2013,39 @@ static void syscall_get_set_args_cb(struct 
> unw_frame_info *info, void *data)
>  {
>   struct syscall_get_set_args *args = data;
>   struct pt_regs *pt = args->regs;
> - unsigned long *krbs, cfm, ndirty;
> + unsigned long *krbs, cfm, ndirty, nlocals, nouts;
>   int i, count;
>  
>   if (unw_unwind_to_user(info) < 0)
>   return;
>  
> + /*
> +  * We get here via a few paths:
> +  * - break instruction: cfm is shared with caller.
> +  *   syscall args are in out= regs, locals are non-empty.
> +  * - epsinstruction: cfm is set by br.call
> +  *   locals don't exist.

typo: epsinstruction

> +  *
> +  * For both cases argguments are reachable in cfm.sof - cfm.sol.

typo: argguments

> +  * CFM: [ ... | sor: 17..14 | sol : 13..7 | sof : 6..0 ]
> +  */
>   cfm = pt->cr_ifs;
> + nlocals = (cfm >> 7) & 0x7f; /* aka sol */
> + nouts = (cfm & 0x7f) - nlocals; /* aka sof - sol */
>   krbs = (unsigned long *)info->task + IA64_RBS_OFFSET/8;
>   ndirty = ia64_rse_num_regs(krbs, krbs + (pt->loadrs >> 19));
>  
>   count = 0;
>   if (in_syscall(pt))
> - count = min_t(int, args->n, cfm & 0x7f);
> + count = min_t(int, args->n, nouts);
>  
> + /* Iterate over outs. */
>   for (i = 0; i < count; i++) {
> + int j = ndirty + nlocals + i + args->i;
>   if (args->rw)
> - *ia64_rse_skip_regs(krbs, ndirty + i + args->i) =
> - args->args[i];
> + *ia64_rse_skip_regs(krbs, j) = args->args[i];
>   else
> - args->args[i] = *ia64_rse_skip_regs(krbs,
> - ndirty + i + args->i);
> + args->args[i] = *ia64_rse_skip_regs(krbs, j);
>   }
>  
>   if (!args->rw) {

This stuff is too ia64 specific, so I cannot properly review this patch,
but it definitely fixes ia64 PTRACE_GET_SYSCALL_INFO on entering syscall.


-- 
ldv


[PATCH] sparc: make copy_thread honor pid namespaces

2021-02-17 Thread Dmitry V. Levin
On sparc, fork and clone syscalls have an unusual semantics of
returning the pid of the parent process to the child process.

Apparently, the implementation did not honor pid namespaces at all,
so the child used to get the pid of its parent in the init namespace.

This bug was found by strace test suite.

Reproducer:

  $ gcc -Wall -O2 -xc - <<'EOF'
  #define _GNU_SOURCE
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  int main(void)
  {
if (unshare(CLONE_NEWPID | CLONE_NEWUSER) < 0)
  err(1, "unshare");
int pid = syscall(__NR_fork);
if (pid < 0)
  err(1, "fork");
fprintf(stderr, "current: %d, parent: %d, fork returned: %d\n",
getpid(), getppid(), pid);
int status;
if (wait() < 0) {
  if (errno == ECHILD)
_exit(0);
  err(1, "wait");
}
return !WIFEXITED(status) || WEXITSTATUS(status) != 0;
  }
  EOF
  $ sh -c ./a.out
  current: 10001, parent: 1, fork returned: 10002
  current: 1, parent: 0, fork returned: 10001

Cc: Eric W. Biederman 
Cc: sta...@vger.kernel.org
Signed-off-by: Dmitry V. Levin 
---

Although the fix seems to be obvious, I have no means to test it myself,
so any help with the testing is much appreciated.

 arch/sparc/kernel/process_32.c | 2 +-
 arch/sparc/kernel/process_64.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
index a02363735915..7a89969befa8 100644
--- a/arch/sparc/kernel/process_32.c
+++ b/arch/sparc/kernel/process_32.c
@@ -368,7 +368,7 @@ int copy_thread(unsigned long clone_flags, unsigned long 
sp, unsigned long arg,
 #endif
 
/* Set the return value for the child. */
-   childregs->u_regs[UREG_I0] = current->pid;
+   childregs->u_regs[UREG_I0] = task_pid_nr_ns(current, 
task_active_pid_ns(p));
childregs->u_regs[UREG_I1] = 1;
 
/* Set the return value for the parent. */
diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
index 6f8c7822fc06..ec97217ab970 100644
--- a/arch/sparc/kernel/process_64.c
+++ b/arch/sparc/kernel/process_64.c
@@ -629,7 +629,7 @@ int copy_thread(unsigned long clone_flags, unsigned long 
sp, unsigned long arg,
t->utraps[0]++;
 
/* Set the return value for the child. */
-   t->kregs->u_regs[UREG_I0] = current->pid;
+   t->kregs->u_regs[UREG_I0] = task_pid_nr_ns(current, 
task_active_pid_ns(p));
t->kregs->u_regs[UREG_I1] = 1;
 
/* Set the second return value for the parent. */
-- 
ldv


[PATCH v2] sparc: make copy_thread honor pid namespaces

2021-02-19 Thread Dmitry V. Levin
On sparc, fork and clone syscalls have an unusual semantics of
returning the pid of the parent process to the child process.

Apparently, the implementation did not honor pid namespaces at all,
so the child used to get the pid of its parent in the init namespace.

Fortunately, most users of these syscalls are not affected by this bug
because they use another register to distinguish the parent process
from its child, and the pid of the parent process is often discarded.

Reproducer:

  $ gcc -Wall -O2 -xc - <<'EOF'
  #define _GNU_SOURCE
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  static void test_fork(void)
  {
int pid = syscall(__NR_fork);
if (pid < 0)
err(1, "fork");
fprintf(stderr, "current: %d, parent: %d, fork returned: %d\n",
getpid(), getppid(), pid);
int status;
if (wait() < 0) {
if (errno == ECHILD)
_exit(0);
err(1, "wait");
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
errx(1, "wait: %#x", status);
  }
  int main(void)
  {
test_fork();
if (unshare(CLONE_NEWPID | CLONE_NEWUSER) < 0)
err(1, "unshare");
test_fork();
return 0;
  }
  EOF
  $ sh -c ./a.out
  current: 10001, parent: 1, fork returned: 10002
  current: 10002, parent: 10001, fork returned: 10001
  current: 10001, parent: 1, fork returned: 10003
  current: 1, parent: 0, fork returned: 10001

This bug was found by strace test suite.

Cc: Eric W. Biederman 
Cc: sta...@vger.kernel.org
Signed-off-by: Dmitry V. Levin 
---

v2: Replaced task_active_pid_ns(p) with current->nsproxy->pid_ns_for_children
as suggested by Eric.

 arch/sparc/kernel/process_32.c | 3 ++-
 arch/sparc/kernel/process_64.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
index a02363735915..3be653e40204 100644
--- a/arch/sparc/kernel/process_32.c
+++ b/arch/sparc/kernel/process_32.c
@@ -368,7 +368,8 @@ int copy_thread(unsigned long clone_flags, unsigned long 
sp, unsigned long arg,
 #endif
 
/* Set the return value for the child. */
-   childregs->u_regs[UREG_I0] = current->pid;
+   childregs->u_regs[UREG_I0] =
+   task_pid_nr_ns(current, current->nsproxy->pid_ns_for_children);
childregs->u_regs[UREG_I1] = 1;
 
/* Set the return value for the parent. */
diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
index 6f8c7822fc06..f53ef5cff46a 100644
--- a/arch/sparc/kernel/process_64.c
+++ b/arch/sparc/kernel/process_64.c
@@ -629,7 +629,8 @@ int copy_thread(unsigned long clone_flags, unsigned long 
sp, unsigned long arg,
t->utraps[0]++;
 
/* Set the return value for the child. */
-   t->kregs->u_regs[UREG_I0] = current->pid;
+   t->kregs->u_regs[UREG_I0] =
+   task_pid_nr_ns(current, current->nsproxy->pid_ns_for_children);
t->kregs->u_regs[UREG_I1] = 1;
 
/* Set the second return value for the parent. */
-- 
ldv


Re: [PATCH] ptrace: add PTRACE_GET_RSEQ_CONFIGURATION request

2021-02-22 Thread Dmitry V. Levin
On Mon, Feb 22, 2021 at 11:04:43AM +0100, Piotr Figiel wrote:
[...]
> --- a/include/uapi/linux/ptrace.h
> +++ b/include/uapi/linux/ptrace.h
> @@ -102,6 +102,14 @@ struct ptrace_syscall_info {
>   };
>  };
>  
> +#define PTRACE_GET_RSEQ_CONFIGURATION0x420f
> +
> +struct ptrace_rseq_configuration {
> + __u64 rseq_abi_pointer;
> + __u32 signature;
> + __u32 pad;
> +};
> +
>  /*
>   * These values are stored in task->ptrace_message
>   * by tracehook_report_syscall_* to describe the current syscall-stop.
> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index 61db50f7ca86..a936af66cf6f 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -31,6 +31,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include  /* for syscall_get_* */
>  
> @@ -779,6 +780,22 @@ static int ptrace_peek_siginfo(struct task_struct *child,
>   return ret;
>  }
>  
> +#ifdef CONFIG_RSEQ
> +static long ptrace_get_rseq_configuration(struct task_struct *task,
> +   unsigned long size, void __user *data)
> +{
> + struct ptrace_rseq_configuration conf = {
> + .rseq_abi_pointer = (u64)(uintptr_t)task->rseq,
> + .signature = task->rseq_sig,
> + };
> +
> + size = min_t(unsigned long, size, sizeof(conf));
> + if (copy_to_user(data, , size))
> + return -EFAULT;
> + return size;
> +}
> +#endif

>From API perspective I suggest for such interfaces to return the amount of
data that could have been written if there was enough room specified, e.g.
in this case it's sizeof(conf) instead of size.


-- 
ldv


Re: [PATCH] ptrace: add PTRACE_GET_RSEQ_CONFIGURATION request

2021-02-22 Thread Dmitry V. Levin
On Mon, Feb 22, 2021 at 09:53:10AM -0500, Mathieu Desnoyers wrote:
> - On Feb 22, 2021, at 6:57 AM, Dmitry V. Levin l...@altlinux.org wrote:
> > On Mon, Feb 22, 2021 at 11:04:43AM +0100, Piotr Figiel wrote:
[...]
> >> +#ifdef CONFIG_RSEQ
> >> +static long ptrace_get_rseq_configuration(struct task_struct *task,
> >> +unsigned long size, void __user *data)
> >> +{
> >> +  struct ptrace_rseq_configuration conf = {
> >> +  .rseq_abi_pointer = (u64)(uintptr_t)task->rseq,
> >> +  .signature = task->rseq_sig,
> >> +  };
> >> +
> >> +  size = min_t(unsigned long, size, sizeof(conf));
> >> +  if (copy_to_user(data, , size))
> >> +  return -EFAULT;
> >> +  return size;
> >> +}
> >> +#endif
> > 
> > From API perspective I suggest for such interfaces to return the amount of
> > data that could have been written if there was enough room specified, e.g.
> > in this case it's sizeof(conf) instead of size.
> 
> Looking at the ptrace(2) man page:
> 
> RETURN VALUE
>On success, the PTRACE_PEEK* requests return the  requested  data  (but
>see NOTES), the PTRACE_SECCOMP_GET_FILTER request returns the number of
>instructions in the BPF program, and other requests return zero.

PTRACE_GET_SYSCALL_INFO returns "the number of bytes available to be
written by the kernel".

It's written in the "DESCRIPTION" section, needs to be mirrored
to "RETURN VALUE" section, thanks for reporting the inconsistency.

>On error, all requests return  -1,  and  errno  is  set  appropriately.
>Since  the  value  returned by a successful PTRACE_PEEK* request may be
>-1, the caller must clear errno before the call, and then check it  af‐
>terward to determine whether or not an error occurred.
> 
> It looks like the usual behavior for ptrace requests would be to return 0 
> when everything
> is OK. Unless there a strong motivation for doing different for this new 
> request, I
> would be tempted to use the same expected behavior than other requests on 
> success:
> return 0.
> 
> Unless there is a strong motivation for returning either size or sizeof(conf) 
> ? If we
> return sizeof(conf) to user-space, it means it should check it and deal with 
> the
> size mismatch. Is that size ever expected to change ?

When adding new interfaces, it's generally a good idea to allow for
future extensions.
If some day in the future the structure is extended, the return value
would be the way to tell userspace what's actually supported by the kernel.


-- 
ldv


[PATCH] uapi: nfnetlink_cthelper.h: fix userspace compilation error

2021-02-22 Thread Dmitry V. Levin
Apparently,  and
 could not be included into the same
compilation unit because of a cut-and-paste typo in the former header.

Fixes: 12f7a505331e6 ("netfilter: add user-space connection tracking helper 
infrastructure")
Cc:  # v3.6
Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/netfilter/nfnetlink_cthelper.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/netfilter/nfnetlink_cthelper.h 
b/include/uapi/linux/netfilter/nfnetlink_cthelper.h
index a13137afc429..70af02092d16 100644
--- a/include/uapi/linux/netfilter/nfnetlink_cthelper.h
+++ b/include/uapi/linux/netfilter/nfnetlink_cthelper.h
@@ -5,7 +5,7 @@
 #define NFCT_HELPER_STATUS_DISABLED0
 #define NFCT_HELPER_STATUS_ENABLED 1
 
-enum nfnl_acct_msg_types {
+enum nfnl_cthelper_msg_types {
NFNL_MSG_CTHELPER_NEW,
NFNL_MSG_CTHELPER_GET,
NFNL_MSG_CTHELPER_DEL,
-- 
ldv


Re: [PATCH v23 3/5] tracing: Allow user-space mapping of the ring-buffer

2024-06-30 Thread Dmitry V. Levin
On Fri, May 10, 2024 at 03:04:32PM +0100, Vincent Donnefort wrote:
[...]
> diff --git a/include/uapi/linux/trace_mmap.h b/include/uapi/linux/trace_mmap.h
> index b682e9925539..bd1066754220 100644
> --- a/include/uapi/linux/trace_mmap.h
> +++ b/include/uapi/linux/trace_mmap.h
> @@ -43,4 +43,6 @@ struct trace_buffer_meta {
>   __u64   Reserved2;
>  };
>  
> +#define TRACE_MMAP_IOCTL_GET_READER  _IO('T', 0x1)
> +

I'm sorry but among all the numbers this one was probably the least
fortunate choice because it collides with TCGETS on most of architectures.

For example, this is how strace output would look like when
TRACE_MMAP_IOCTL_GET_READER support is added:

$ strace -e ioctl stty
ioctl(0, TCGETS or TRACE_MMAP_IOCTL_GET_READER, {c_iflag=ICRNL|IXON, 
c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, 
c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0

Even though ioctl numbers are inherently not unique, TCGETS is
a very traditional one, so it would be great if you could change
TRACE_MMAP_IOCTL_GET_READER to avoid this collision.

Given that _IO('T', 0x1) is _IOC(_IOC_NONE, 'T', 0x1, 0),
something like _IOC(_IOC_NONE, 'T', 0x1, 0x1) should be OK.


-- 
ldv



[PATCH] uapi: change TRACE_MMAP_IOCTL_GET_READER to avoid collision with TCGETS

2024-06-30 Thread Dmitry V. Levin
The number that was initially chosen for TRACE_MMAP_IOCTL_GET_READER,
unfortunately, collides with TCGETS on most of architectures.

For example, this is how strace output would look like when
support for this value of TRACE_MMAP_IOCTL_GET_READER is added:

$ strace -e ioctl stty
ioctl(0, TCGETS or TRACE_MMAP_IOCTL_GET_READER, {c_iflag=ICRNL|IXON, 
c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR,
+c_cflag=B38400|CS8|CREAD, 
c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0

Even though ioctl numbers are inherently not unique, TCGETS
is a very traditional one, so let's change the value of
TRACE_MMAP_IOCTL_GET_READER a bit to avoid this collision.

Given that _IO('T', 0x1) is _IOC(_IOC_NONE, 'T', 0x1, 0),
something like _IOC(_IOC_NONE, 'T', 0x1, 0x1) should be OK.

Fixes: cf9f0f7c4c5bb ("tracing: Allow user-space mapping of the ring-buffer")
Signed-off-by: Dmitry V. Levin 
---
 include/uapi/linux/trace_mmap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/trace_mmap.h b/include/uapi/linux/trace_mmap.h
index bd1066754220..cb858f1b8367 100644
--- a/include/uapi/linux/trace_mmap.h
+++ b/include/uapi/linux/trace_mmap.h
@@ -43,6 +43,6 @@ struct trace_buffer_meta {
__u64   Reserved2;
 };
 
-#define TRACE_MMAP_IOCTL_GET_READER_IO('T', 0x1)
+#define TRACE_MMAP_IOCTL_GET_READER_IOC(_IOC_NONE, 'T', 0x1, 0x1)
 
 #endif /* _TRACE_MMAP_H_ */
-- 
ldv



Re: [PATCH v23 3/5] tracing: Allow user-space mapping of the ring-buffer

2024-07-02 Thread Dmitry V. Levin
On Tue, Jul 02, 2024 at 11:32:53AM -0400, Mathieu Desnoyers wrote:
[...]
> Note that user events also has this issue: the ioctl is not reserved in
> the ioctl-number.rst list. See include/uapi/linux/user_events.h:
> 
> #define DIAG_IOC_MAGIC '*'
> 
> /* Request to register a user_event */
> #define DIAG_IOCSREG _IOWR(DIAG_IOC_MAGIC, 0, struct user_reg *)
> 
> /* Request to delete a user_event */
> #define DIAG_IOCSDEL _IOW(DIAG_IOC_MAGIC, 1, char *)
> 
> /* Requests to unregister a user_event */
> #define DIAG_IOCSUNREG _IOW(DIAG_IOC_MAGIC, 2, struct user_unreg*)
> 
> Where '*' maps to Code 0x2A. Looking at the list I don't see any
> conflicts there, but we should definitely add it.
> 
> If we use '*' for user events already, perhaps we'd want to consider
> using the same range for the ring buffer ioctls ? Arguably one is
> about instrumentation and the other is about ring buffer interaction
> (data transport), but those are both related to tracing.

FWIW, I've checked the list of ioctls known to strace and can confirm that
currently there are no more users of 0x2a ioctl code besides these three
DIAG_* ioctls.


-- 
ldv



Re: [PATCH v23 3/5] tracing: Allow user-space mapping of the ring-buffer

2024-07-02 Thread Dmitry V. Levin
On Tue, Jul 02, 2024 at 11:18:07AM -0400, Steven Rostedt wrote:
> On Tue, 2 Jul 2024 10:36:03 -0400
> Mathieu Desnoyers  wrote:
> 
> > > I can send a patch this week to update it. Or feel free to send a patch
> > > yourself.  
> > 
> > You need to reserve an unused ioctl Code and Seq# range within:
> > 
> > Documentation/userspace-api/ioctl/ioctl-number.rst
> 
> Ug, it's been so long, I completely forgot about that file.
> 
> Thanks for catching this.
> 
> > 
> > Otherwise this duplicate will confuse all system call instrumentation
> > tooling.
> 
> Agreed, what if we did this then:
> 
> -- Steve
> 
> diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst 
> b/Documentation/userspace-api/ioctl/ioctl-number.rst
> index a141e8e65c5d..9a97030c6c8d 100644
> --- a/Documentation/userspace-api/ioctl/ioctl-number.rst
> +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
> @@ -186,6 +186,7 @@ Code  Seq#Include File
>Comments
>  'Q'   alllinux/soundcard.h
>  'R'   00-1F  linux/random.h  
> conflict!
>  'R'   01 linux/rfkill.h  
> conflict!
> +'R'   20-2F  linux/trace_mmap.h
>  'R'   C0-DF  net/bluetooth/rfcomm.h
>  'R'   E0 uapi/linux/fsl_mc.h
>  'S'   alllinux/cdrom.h   
> conflict!

Just in case, I've checked the list of ioctls known to strace and can
confirm that there are no users of 'R' ioctl code in 0x20..0x2f range yet.

By the way, this file is definitely not up to date, the 'R' part of it
should have contained the following:

'R'   00-1F  uapi/linux/random.h conflict!
'R'   01-02  uapi/linux/rfkill.h conflict!
'R'   01-0D  uapi/misc/fastrpc.h conflict!
'R'   C0-DF  net/bluetooth/rfcomm.h
'R'   E0 uapi/linux/fsl_mc.h


-- 
ldv



[tip:x86/urgent] x86/signal: Fix restart_syscall number for x32 tasks

2015-12-05 Thread tip-bot for Dmitry V. Levin
Commit-ID:  22eab1108781eff09961ae7001704f7bd8fb1dce
Gitweb: http://git.kernel.org/tip/22eab1108781eff09961ae7001704f7bd8fb1dce
Author: Dmitry V. Levin <l...@altlinux.org>
AuthorDate: Tue, 1 Dec 2015 00:54:36 +0300
Committer:  Thomas Gleixner <t...@linutronix.de>
CommitDate: Sat, 5 Dec 2015 18:52:14 +0100

x86/signal: Fix restart_syscall number for x32 tasks

When restarting a syscall with regs->ax == -ERESTART_RESTARTBLOCK,
regs->ax is assigned to a restart_syscall number.  For x32 tasks, this
syscall number must have __X32_SYSCALL_BIT set, otherwise it will be
an x86_64 syscall number instead of a valid x32 syscall number. This
issue has been there since the introduction of x32.

Reported-by: strace/tests/restart_syscall.test
Reported-and-tested-by: Elvira Khabirova <lineprint...@gmail.com>
Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
Cc: Elvira Khabirova <lineprint...@gmail.com>
Cc: sta...@vger.kernel.org
Link: http://lkml.kernel.org/r/20151130215436.ga25...@altlinux.org
Signed-off-by: Thomas Gleixner <t...@linutronix.de>
---
 arch/x86/kernel/signal.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b7ffb7c..cb6282c 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -690,12 +690,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
signal_setup_done(failed, ksig, stepping);
 }
 
-#ifdef CONFIG_X86_32
-#define NR_restart_syscall __NR_restart_syscall
-#else /* !CONFIG_X86_32 */
-#define NR_restart_syscall \
-   test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : 
__NR_restart_syscall
-#endif /* CONFIG_X86_32 */
+static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
+{
+#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+   return __NR_restart_syscall;
+#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
+   return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
+   __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
+#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
+}
 
 /*
  * Note that 'init' is a special process: it doesn't get signals it doesn't
@@ -724,7 +727,7 @@ void do_signal(struct pt_regs *regs)
break;
 
case -ERESTART_RESTARTBLOCK:
-   regs->ax = NR_restart_syscall;
+   regs->ax = get_nr_restart_syscall(regs);
regs->ip -= 2;
break;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86: Use compat version for preadv2 and pwritev2

2016-05-12 Thread tip-bot for Dmitry V. Levin
Commit-ID:  9a7a076e8e4ffcfec05e3cafe4c4e31d41ddbaa0
Gitweb: http://git.kernel.org/tip/9a7a076e8e4ffcfec05e3cafe4c4e31d41ddbaa0
Author: Dmitry V. Levin <l...@altlinux.org>
AuthorDate: Wed, 11 May 2016 11:48:17 +0300
Committer:  Thomas Gleixner <t...@linutronix.de>
CommitDate: Thu, 12 May 2016 14:27:13 +0200

x86: Use compat version for preadv2 and pwritev2

Similar to preadv and pwritev, preadv2 and pwritev2 need compat entries
in the 32-bit syscall table.

This bug was found by strace test suite.

Fixes: 4babf2c5efb7 ("x86: wire up preadv2 and pwritev2")
Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
Acked-by: Christoph Hellwig <h...@lst.de>
Link: http://lkml.kernel.org/r/20160511084817.ga29...@altlinux.org
Signed-off-by: Thomas Gleixner <t...@linutronix.de>

---
 arch/x86/entry/syscalls/syscall_32.tbl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl 
b/arch/x86/entry/syscalls/syscall_32.tbl
index b30dd81..4cddd17 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -384,5 +384,5 @@
 375i386membarrier  sys_membarrier
 376i386mlock2  sys_mlock2
 377i386copy_file_range sys_copy_file_range
-378i386preadv2 sys_preadv2
-379i386pwritev2sys_pwritev2
+378i386preadv2 sys_preadv2 
compat_sys_preadv2
+379i386pwritev2sys_pwritev2
compat_sys_pwritev2


[tip:sched/urgent] sched/headers/uapi: Fix linux/sched/types.h userspace compilation errors

2017-07-08 Thread tip-bot for Dmitry V. Levin
Commit-ID:  242fc35290bd8cf0effc6e3474e3a417985de2f3
Gitweb: http://git.kernel.org/tip/242fc35290bd8cf0effc6e3474e3a417985de2f3
Author: Dmitry V. Levin <l...@altlinux.org>
AuthorDate: Wed, 5 Jul 2017 19:23:28 +0300
Committer:  Ingo Molnar <mi...@kernel.org>
CommitDate: Sat, 8 Jul 2017 11:17:55 +0200

sched/headers/uapi: Fix linux/sched/types.h userspace compilation errors

Consistently use types provided by  to fix the following
linux/sched/types.h userspace compilation errors:

  /usr/include/linux/sched/types.h:57:2: error: unknown type name 'u32'
u32 size;
  ...
  u64 sched_period;

Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: sta...@vger.kernel.org # v4.12
Fixes: e2d1e2aec572 ("sched/headers: Move various ABI definitions to 
")
Link: http://lkml.kernel.org/r/20170705162328.ga11...@altlinux.org
Signed-off-by: Ingo Molnar <mi...@kernel.org>
---
 include/uapi/linux/sched/types.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h
index 307acbc..34b81aa 100644
--- a/include/uapi/linux/sched/types.h
+++ b/include/uapi/linux/sched/types.h
@@ -54,21 +54,21 @@ struct sched_param {
  * available in the scheduling class file or in Documentation/.
  */
 struct sched_attr {
-   u32 size;
+   __u32 size;
 
-   u32 sched_policy;
-   u64 sched_flags;
+   __u32 sched_policy;
+   __u64 sched_flags;
 
/* SCHED_NORMAL, SCHED_BATCH */
-   s32 sched_nice;
+   __s32 sched_nice;
 
/* SCHED_FIFO, SCHED_RR */
-   u32 sched_priority;
+   __u32 sched_priority;
 
/* SCHED_DEADLINE */
-   u64 sched_runtime;
-   u64 sched_deadline;
-   u64 sched_period;
+   __u64 sched_runtime;
+   __u64 sched_deadline;
+   __u64 sched_period;
 };
 
 #endif /* _UAPI_LINUX_SCHED_TYPES_H */


[tip:x86/pti] x86/uapi: Fix asm/bootparam.h userspace compilation errors

2018-04-05 Thread tip-bot for Dmitry V. Levin
Commit-ID:  9820e1c3376c641299624dd24646aed3167ad5b1
Gitweb: https://git.kernel.org/tip/9820e1c3376c641299624dd24646aed3167ad5b1
Author: Dmitry V. Levin <l...@altlinux.org>
AuthorDate: Thu, 5 Apr 2018 07:32:10 +0300
Committer:  Ingo Molnar <mi...@kernel.org>
CommitDate: Thu, 5 Apr 2018 10:05:21 +0200

x86/uapi: Fix asm/bootparam.h userspace compilation errors

Consistently use types provided by  to fix the following
asm/bootparam.h userspace compilation errors:

/usr/include/asm/bootparam.h:140:2: error: unknown type name 'u16'
  u16 version;
/usr/include/asm/bootparam.h:141:2: error: unknown type name 'u16'
  u16 compatible_version;
/usr/include/asm/bootparam.h:142:2: error: unknown type name 'u16'
  u16 pm_timer_address;
/usr/include/asm/bootparam.h:143:2: error: unknown type name 'u16'
  u16 num_cpus;
/usr/include/asm/bootparam.h:144:2: error: unknown type name 'u64'
  u64 pci_mmconfig_base;
/usr/include/asm/bootparam.h:145:2: error: unknown type name 'u32'
  u32 tsc_khz;
/usr/include/asm/bootparam.h:146:2: error: unknown type name 'u32'
  u32 apic_khz;
/usr/include/asm/bootparam.h:147:2: error: unknown type name 'u8'
  u8 standard_ioapic;
/usr/include/asm/bootparam.h:148:2: error: unknown type name 'u8'
  u8 cpu_ids[255];

Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
Acked-by: Jan Kiszka <jan.kis...@siemens.com>
Cc: <sta...@vger.kernel.org> # v4.16
Cc: Linus Torvalds <torva...@linux-foundation.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Fixes: 4a362601baa6 ("x86/jailhouse: Add infrastructure for running in non-root 
cell")
Link: http://lkml.kernel.org/r/20180405043210.ga13...@altlinux.org
Signed-off-by: Ingo Molnar <mi...@kernel.org>
---
 arch/x86/include/uapi/asm/bootparam.h | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/uapi/asm/bootparam.h 
b/arch/x86/include/uapi/asm/bootparam.h
index aebf60357758..a06cbf019744 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -137,15 +137,15 @@ struct boot_e820_entry {
  * setup data structure.
  */
 struct jailhouse_setup_data {
-   u16 version;
-   u16 compatible_version;
-   u16 pm_timer_address;
-   u16 num_cpus;
-   u64 pci_mmconfig_base;
-   u32 tsc_khz;
-   u32 apic_khz;
-   u8  standard_ioapic;
-   u8  cpu_ids[255];
+   __u16   version;
+   __u16   compatible_version;
+   __u16   pm_timer_address;
+   __u16   num_cpus;
+   __u64   pci_mmconfig_base;
+   __u32   tsc_khz;
+   __u32   apic_khz;
+   __u8standard_ioapic;
+   __u8cpu_ids[255];
 } __attribute__((packed));
 
 /* The so-called "zeropage" */


[tip:x86/pti] x86/uapi: Fix asm/bootparam.h userspace compilation errors

2018-04-05 Thread tip-bot for Dmitry V. Levin
Commit-ID:  9820e1c3376c641299624dd24646aed3167ad5b1
Gitweb: https://git.kernel.org/tip/9820e1c3376c641299624dd24646aed3167ad5b1
Author: Dmitry V. Levin 
AuthorDate: Thu, 5 Apr 2018 07:32:10 +0300
Committer:  Ingo Molnar 
CommitDate: Thu, 5 Apr 2018 10:05:21 +0200

x86/uapi: Fix asm/bootparam.h userspace compilation errors

Consistently use types provided by  to fix the following
asm/bootparam.h userspace compilation errors:

/usr/include/asm/bootparam.h:140:2: error: unknown type name 'u16'
  u16 version;
/usr/include/asm/bootparam.h:141:2: error: unknown type name 'u16'
  u16 compatible_version;
/usr/include/asm/bootparam.h:142:2: error: unknown type name 'u16'
  u16 pm_timer_address;
/usr/include/asm/bootparam.h:143:2: error: unknown type name 'u16'
  u16 num_cpus;
/usr/include/asm/bootparam.h:144:2: error: unknown type name 'u64'
  u64 pci_mmconfig_base;
/usr/include/asm/bootparam.h:145:2: error: unknown type name 'u32'
  u32 tsc_khz;
/usr/include/asm/bootparam.h:146:2: error: unknown type name 'u32'
  u32 apic_khz;
/usr/include/asm/bootparam.h:147:2: error: unknown type name 'u8'
  u8 standard_ioapic;
/usr/include/asm/bootparam.h:148:2: error: unknown type name 'u8'
  u8 cpu_ids[255];

Signed-off-by: Dmitry V. Levin 
Acked-by: Jan Kiszka 
Cc:  # v4.16
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Fixes: 4a362601baa6 ("x86/jailhouse: Add infrastructure for running in non-root 
cell")
Link: http://lkml.kernel.org/r/20180405043210.ga13...@altlinux.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/uapi/asm/bootparam.h | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/uapi/asm/bootparam.h 
b/arch/x86/include/uapi/asm/bootparam.h
index aebf60357758..a06cbf019744 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -137,15 +137,15 @@ struct boot_e820_entry {
  * setup data structure.
  */
 struct jailhouse_setup_data {
-   u16 version;
-   u16 compatible_version;
-   u16 pm_timer_address;
-   u16 num_cpus;
-   u64 pci_mmconfig_base;
-   u32 tsc_khz;
-   u32 apic_khz;
-   u8  standard_ioapic;
-   u8  cpu_ids[255];
+   __u16   version;
+   __u16   compatible_version;
+   __u16   pm_timer_address;
+   __u16   num_cpus;
+   __u64   pci_mmconfig_base;
+   __u32   tsc_khz;
+   __u32   apic_khz;
+   __u8standard_ioapic;
+   __u8cpu_ids[255];
 } __attribute__((packed));
 
 /* The so-called "zeropage" */


[tip:sched/urgent] sched/headers/uapi: Fix linux/sched/types.h userspace compilation errors

2017-07-08 Thread tip-bot for Dmitry V. Levin
Commit-ID:  242fc35290bd8cf0effc6e3474e3a417985de2f3
Gitweb: http://git.kernel.org/tip/242fc35290bd8cf0effc6e3474e3a417985de2f3
Author: Dmitry V. Levin 
AuthorDate: Wed, 5 Jul 2017 19:23:28 +0300
Committer:  Ingo Molnar 
CommitDate: Sat, 8 Jul 2017 11:17:55 +0200

sched/headers/uapi: Fix linux/sched/types.h userspace compilation errors

Consistently use types provided by  to fix the following
linux/sched/types.h userspace compilation errors:

  /usr/include/linux/sched/types.h:57:2: error: unknown type name 'u32'
u32 size;
  ...
  u64 sched_period;

Signed-off-by: Dmitry V. Levin 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: sta...@vger.kernel.org # v4.12
Fixes: e2d1e2aec572 ("sched/headers: Move various ABI definitions to 
")
Link: http://lkml.kernel.org/r/20170705162328.ga11...@altlinux.org
Signed-off-by: Ingo Molnar 
---
 include/uapi/linux/sched/types.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h
index 307acbc..34b81aa 100644
--- a/include/uapi/linux/sched/types.h
+++ b/include/uapi/linux/sched/types.h
@@ -54,21 +54,21 @@ struct sched_param {
  * available in the scheduling class file or in Documentation/.
  */
 struct sched_attr {
-   u32 size;
+   __u32 size;
 
-   u32 sched_policy;
-   u64 sched_flags;
+   __u32 sched_policy;
+   __u64 sched_flags;
 
/* SCHED_NORMAL, SCHED_BATCH */
-   s32 sched_nice;
+   __s32 sched_nice;
 
/* SCHED_FIFO, SCHED_RR */
-   u32 sched_priority;
+   __u32 sched_priority;
 
/* SCHED_DEADLINE */
-   u64 sched_runtime;
-   u64 sched_deadline;
-   u64 sched_period;
+   __u64 sched_runtime;
+   __u64 sched_deadline;
+   __u64 sched_period;
 };
 
 #endif /* _UAPI_LINUX_SCHED_TYPES_H */


[tip:x86/urgent] x86: Use compat version for preadv2 and pwritev2

2016-05-12 Thread tip-bot for Dmitry V. Levin
Commit-ID:  9a7a076e8e4ffcfec05e3cafe4c4e31d41ddbaa0
Gitweb: http://git.kernel.org/tip/9a7a076e8e4ffcfec05e3cafe4c4e31d41ddbaa0
Author: Dmitry V. Levin 
AuthorDate: Wed, 11 May 2016 11:48:17 +0300
Committer:  Thomas Gleixner 
CommitDate: Thu, 12 May 2016 14:27:13 +0200

x86: Use compat version for preadv2 and pwritev2

Similar to preadv and pwritev, preadv2 and pwritev2 need compat entries
in the 32-bit syscall table.

This bug was found by strace test suite.

Fixes: 4babf2c5efb7 ("x86: wire up preadv2 and pwritev2")
Signed-off-by: Dmitry V. Levin 
Acked-by: Christoph Hellwig 
Link: http://lkml.kernel.org/r/20160511084817.ga29...@altlinux.org
Signed-off-by: Thomas Gleixner 

---
 arch/x86/entry/syscalls/syscall_32.tbl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl 
b/arch/x86/entry/syscalls/syscall_32.tbl
index b30dd81..4cddd17 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -384,5 +384,5 @@
 375i386membarrier  sys_membarrier
 376i386mlock2  sys_mlock2
 377i386copy_file_range sys_copy_file_range
-378i386preadv2 sys_preadv2
-379i386pwritev2sys_pwritev2
+378i386preadv2 sys_preadv2 
compat_sys_preadv2
+379i386pwritev2sys_pwritev2
compat_sys_pwritev2


[tip:x86/urgent] x86/signal: Fix restart_syscall number for x32 tasks

2015-12-05 Thread tip-bot for Dmitry V. Levin
Commit-ID:  22eab1108781eff09961ae7001704f7bd8fb1dce
Gitweb: http://git.kernel.org/tip/22eab1108781eff09961ae7001704f7bd8fb1dce
Author: Dmitry V. Levin 
AuthorDate: Tue, 1 Dec 2015 00:54:36 +0300
Committer:  Thomas Gleixner 
CommitDate: Sat, 5 Dec 2015 18:52:14 +0100

x86/signal: Fix restart_syscall number for x32 tasks

When restarting a syscall with regs->ax == -ERESTART_RESTARTBLOCK,
regs->ax is assigned to a restart_syscall number.  For x32 tasks, this
syscall number must have __X32_SYSCALL_BIT set, otherwise it will be
an x86_64 syscall number instead of a valid x32 syscall number. This
issue has been there since the introduction of x32.

Reported-by: strace/tests/restart_syscall.test
Reported-and-tested-by: Elvira Khabirova 
Signed-off-by: Dmitry V. Levin 
Cc: Elvira Khabirova 
Cc: sta...@vger.kernel.org
Link: http://lkml.kernel.org/r/20151130215436.ga25...@altlinux.org
Signed-off-by: Thomas Gleixner 
---
 arch/x86/kernel/signal.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b7ffb7c..cb6282c 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -690,12 +690,15 @@ handle_signal(struct ksignal *ksig, struct pt_regs *regs)
signal_setup_done(failed, ksig, stepping);
 }
 
-#ifdef CONFIG_X86_32
-#define NR_restart_syscall __NR_restart_syscall
-#else /* !CONFIG_X86_32 */
-#define NR_restart_syscall \
-   test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : 
__NR_restart_syscall
-#endif /* CONFIG_X86_32 */
+static inline unsigned long get_nr_restart_syscall(const struct pt_regs *regs)
+{
+#if defined(CONFIG_X86_32) || !defined(CONFIG_X86_64)
+   return __NR_restart_syscall;
+#else /* !CONFIG_X86_32 && CONFIG_X86_64 */
+   return test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall :
+   __NR_restart_syscall | (regs->orig_ax & __X32_SYSCALL_BIT);
+#endif /* CONFIG_X86_32 || !CONFIG_X86_64 */
+}
 
 /*
  * Note that 'init' is a special process: it doesn't get signals it doesn't
@@ -724,7 +727,7 @@ void do_signal(struct pt_regs *regs)
break;
 
case -ERESTART_RESTARTBLOCK:
-   regs->ax = NR_restart_syscall;
+   regs->ax = get_nr_restart_syscall(regs);
regs->ip -= 2;
break;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


<    2   3   4   5   6   7