Superblock notifications
Subsystems (7)
cover Superblock notifications
Hi,
Google has been using an out-of-tree mechanism for error notification in Ext4 and we decided it is time to push for an upstream solution. This would surely fit on top of David's notification work.
This patchset is an attempt to restart that discussion. It forward ports some code from David on top of Linus tree, adds features to watch_queue and implements ext4 support.
The new notifications are designed after ext4 messages, so it exposes notifications types to fit that filesystem, but it doesn't change much to other filesystems, so it should be easily extensible.
I'm aware of the discussion around fsinfo, but I'd like to ask if there are other missing pieces and what we could do to help that work go upstream. From a previous mailing list discussion, Linus complained about lack of users as a main reason for it to not be merged, so hey! :)
In addition, I'd like to ask for feedback on the current implementation, specifically regarding the passing of extra unformatted information at the end of the notification and the ext4 support.
The work, as shared on this patchset can be found at:
https://gitlab.collabora.com/krisman/linux.git -b ext4-error-notifications
And there is an example code at:
https://gitlab.collabora.com/krisman/ext4-watcher
I'm Cc'ing Khazhismel Kumykov, from Google, who can provide more information about their use case, if requested.
David Howells (3):
watch_queue: Make watch_sizeof() check record size
security: Add hooks to rule on setting a watch for superblock
vfs: Add superblock notifications
Gabriel Krisman Bertazi (4):
watch_queue: Support a text field at the end of the notification
vfs: Include origin of the SB error notification
fs: Add more superblock error subtypes
ext4: Implement SB error notification through watch_sb
arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + fs/Kconfig | 12 ++ fs/ext4/super.c | 32 +++- fs/super.c | 127 +++++++++++++++ include/linux/fs.h | 207 +++++++++++++++++++++++++ include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 4 + include/linux/security.h | 13 ++ include/linux/syscalls.h | 2 + include/linux/watch_queue.h | 21 ++- include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/watch_queue.h | 68 +++++++- kernel/sys_ni.c | 3 + kernel/watch_queue.c | 29 +++- security/security.c | 7 + 16 files changed, 514 insertions(+), 18 deletions(-)
Signature · 1 line
2.28.0
RFC PATCH 1/7 watch_queue: Make watch_sizeof() check record size
From: David Howells <[email protected]>
Make watch_sizeof() give a build error if the size of the struct won't fit into the size field in the header.
--- include/linux/watch_queue.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/linux/watch_queue.h +6 -1
@@ -120,7 +120,12 @@ static inline void remove_watch_list(struct watch_list *wlist, u64 id)* watch_sizeof - Calculate the information part of the size of a watch record, * given the structure size. */ -#define watch_sizeof (STRUCT ) (sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT) +#define watch_sizeof (STRUCT ) \ + ({ \ + size_t max = WATCH_INFO_LENGTH >> WATCH_INFO_LENGTH__SHIFT; \ + BUILD_BUG_ON(sizeof(STRUCT) > max); \ + sizeof(STRUCT) << WATCH_INFO_LENGTH__SHIFT; \ + })#else static inline int watch_queue_init (struct pipe_inode_info *pipe)
Signature · 1 line
2.28.0
RFC PATCH 2/7 security: Add hooks to rule on setting a watch for superblock
In reply to Gabriel Krisman BertaziFrom: David Howells <[email protected]>
Add security hooks that will allow an LSM to rule on whether or not a watch may be set for a supperblock.
--- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 4 ++++ include/linux/security.h | 13 +++++++++++++ security/security.c | 7 +++++++ 4 files changed, 25 insertions(+)
include/linux/lsm_hook_defs.h +1 -0
@@ -261,6 +261,7 @@ LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx,#if defined(CONFIG_SECURITY ) && defined(CONFIG_WATCH_QUEUE ) LSM_HOOK(int, 0, post_notification, const struct cred *w_cred, const struct cred *cred, struct watch_notification *n) +LSM_HOOK(int, 0, watch_sb, struct super_block *sb)#endif /* CONFIG_SECURITY && CONFIG_WATCH_QUEUE */ #if defined(CONFIG_SECURITY ) && defined(CONFIG_KEY_NOTIFICATIONS )
include/linux/lsm_hooks.h +4 -0
@@ -1475,6 +1475,10 @@* @w_cred: The credentials of the whoever set the watch. * @cred: The event-triggerer's credentials * @n: The notification being posted +* @watch_sb: +* Check to see if a process is allowed to watch for event notifications +* from a superblock. +* @sb: The superblock to watch. * * @watch_key: * Check to see if a process is allowed to watch for event notifications
include/linux/security.h +13 -0
@@ -456,6 +456,11 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);int security_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen);int security_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen);int security_locked_down (enum lockdown_reason what); + +#ifdef CONFIG_WATCH_QUEUE +int security_watch_sb (struct super_block *sb); +#endif /* CONFIG_WATCH_QUEUE */ +#else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier (enum lsm_event event,void *data)
@@ -1304,6 +1309,14 @@ static inline int security_locked_down(enum lockdown_reason what) {return 0 ; } + +#ifdef CONFIG_WATCH_QUEUE +static inline int security_watch_sb (struct super_block *sb) +{ +return 0 ; +} +#endif /* CONFIG_WATCH_QUEUE */ +#endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY ) && defined(CONFIG_WATCH_QUEUE )
security/security.c +7 -0
@@ -2068,12 +2068,19 @@ int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)EXPORT_SYMBOL (security_inode_getsecctx);#ifdef CONFIG_WATCH_QUEUE +int security_post_notification (const struct cred *w_cred,const struct cred *cred,struct watch_notification *n) {return call_int_hook (post_notification,0 , w_cred, cred, n); } + +int security_watch_sb (struct super_block *sb) +{ +return call_int_hook (watch_sb,0 , sb); +} +#endif /* CONFIG_WATCH_QUEUE */ #ifdef CONFIG_KEY_NOTIFICATIONS
Signature · 1 line
2.28.0
RFC PATCH 3/7 watch_queue: Support a text field at the end of the notification
In reply to Gabriel Krisman BertaziThis allow notifications to send text information to userspace without having to copy it to a temporary buffer to then copy to the ring. One use case to pass text information in notifications is for error reporting, where more debug information might be needed, but we don't want to explode the number of subtypes of notifications. For instance, ext4 can have a single inode error notification subtype, and pass more information on the cause of the error in this field.
--- include/linux/watch_queue.h | 14 ++++++++++++-- kernel/watch_queue.c | 29 ++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-)
include/linux/watch_queue.h +12 -2
@@ -79,7 +79,7 @@ struct watch_list {extern void __post_watch_notification (struct watch_list *,struct watch_notification *,const struct cred *, -u64 ); +u64 ,const char *,va_list *);extern struct watch_queue *get_watch_queue (int );extern void put_watch_queue (struct watch_queue *);extern void init_watch (struct watch *,struct watch_queue *);
@@ -105,7 +105,17 @@ static inline void post_watch_notification(struct watch_list *wlist, u64 id) {if (unlikely (wlist)) -__post_watch_notification (wlist, n, cred, id); +__post_watch_notification (wlist, n, cred, id,NULL ,NULL ); +} + +static inline void post_watch_notification_string (struct watch_list *wlist, +struct watch_notification *n, +const struct cred *cred, +u64 id,const char *fmt, +va_list *args) +{ +if (unlikely (wlist)) +__post_watch_notification (wlist, n, cred, id, fmt, args); }static inline void remove_watch_list (struct watch_list *wlist,u64 id)
kernel/watch_queue.c +24 -5
@@ -70,13 +70,15 @@ static const struct pipe_buf_operations watch_queue_pipe_buf_ops = {* Post a notification to a watch queue. */ static bool post_one_notification (struct watch_queue *wqueue, -struct watch_notification *n) +struct watch_notification *n, +const char *fmt,va_list *args) {void *p;struct pipe_inode_info *pipe = wqueue->pipe;struct pipe_buffer *buf;struct page *page;unsigned int head, tail, mask, note, offset, len; +int wlen =0 ;bool done = false;if (!pipe)
@@ -102,6 +104,23 @@ static bool post_one_notification(struct watch_queue *wqueue,get_page (page); len = n->info &WATCH_INFO_LENGTH ; p =kmap_atomic (page); +/* +* Write the tail description before the actual header, because +* the string needs to be generated to calculate the final +* notification size, that is passed in the header. +*/ +if (fmt) { + wlen =vscnprintf (p + offset + len,WATCH_INFO_LENGTH - len, + fmt, args? *args :NULL ); + wlen +=1 ;/* vscnprintf doesn't include '\0' */ +if (wlen >0 ) { + n->info = n->info & ~WATCH_INFO_LENGTH ; + n->info |= (len + wlen) &WATCH_INFO_LENGTH ; + }else { +/* Drop errors when writting the extra string. */ + wlen =0 ; + } + }memcpy (p + offset, n, len);kunmap_atomic (p);
@@ -110,7 +129,7 @@ static bool post_one_notification(struct watch_queue *wqueue, buf->private = (unsigned long )wqueue; buf->ops = &watch_queue_pipe_buf_ops; buf->offset = offset; - buf->len = len; + buf->len = (len + wlen); buf->flags =PIPE_BUF_FLAG_WHOLE ; pipe->head = head +1 ;
@@ -175,7 +194,7 @@ static bool filter_watch_notification(const struct watch_filter *wf,void __post_watch_notification (struct watch_list *wlist,struct watch_notification *n,const struct cred *cred, -u64 id) +u64 id,const char *fmt,va_list *args) {const struct watch_filter *wf;struct watch_queue *wqueue;
@@ -202,7 +221,7 @@ void __post_watch_notification(struct watch_list *wlist,if (security_post_notification (watch->cred, cred, n) <0 )continue ; -post_one_notification (wqueue, n); +post_one_notification (wqueue, n, fmt, args); }rcu_read_unlock ();
@@ -522,7 +541,7 @@ int remove_watch_from_object(struct watch_list *wlist, struct watch_queue *wq,* protecting *wqueue from deallocation. */ if (wqueue) { -post_one_notification (wqueue, &n.watch); +post_one_notification (wqueue, &n.watch,NULL ,NULL );spin_lock_bh (&wqueue->lock);
Signature · 1 line
2.28.0
RFC PATCH 4/7 vfs: Add superblock notifications
In reply to Gabriel Krisman BertaziFrom: David Howells <[email protected]>
Add a superblock event notification facility whereby notifications about superblock events, such as I/O errors (EIO), quota limits being hit (EDQUOT) and running out of space (ENOSPC) can be reported to a monitoring process asynchronously. Note that this does not cover vfsmount topology changes. watch_mount() is used for that.
Records are of the following format:
struct superblock_notification {
struct watch_notification watch;
__u64 sb_id;
} *n;Where:
n->watch.type will be WATCH_TYPE_SB_NOTIFY. n->watch.subtype will indicate the type of event, such as NOTIFY_SUPERBLOCK_READONLY. n->watch.info & WATCH_INFO_LENGTH will indicate the length of the record. n->watch.info & WATCH_INFO_ID will be the fifth argument to watch_sb(), shifted. n->watch.info & NOTIFY_SUPERBLOCK_IS_NOW_RO will be used for NOTIFY_SUPERBLOCK_READONLY, being set if the superblock becomes R/O, and being cleared otherwise. n->sb_id will be the ID of the superblock, as can be retrieved with the fsinfo() syscall, as part of the fsinfo_sb_notifications attribute in the the watch_id field.
Note that it is permissible for event records to be of variable length - or, at least, the length may be dependent on the subtype. Note also that the queue can be shared between multiple notifications of various types.
--- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + fs/Kconfig | 12 +++ fs/super.c | 127 +++++++++++++++++++++++++ include/linux/fs.h | 83 ++++++++++++++++ include/linux/syscalls.h | 2 + include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/watch_queue.h | 32 ++++++- kernel/sys_ni.c | 3 + 9 files changed, 263 insertions(+), 2 deletions(-)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -445,3 +445,4 @@ 438 i386 pidfd_getfd sys_pidfd_getfd 439 i386 faccessat2 sys_faccessat2 440 i386 process_madvise sys_process_madvise +441 i386 watch_sb sys_watch_sb
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -362,6 +362,7 @@ 438 common pidfd_getfd sys_pidfd_getfd 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise +441 common watch_sb sys_watch_sb # # x32-specific system call numbers start at 512 to avoid cache impact
fs/Kconfig +12 -0
@@ -117,6 +117,18 @@ source "fs/verity/Kconfig" source "fs/notify/Kconfig" +config SB_NOTIFICATIONS + bool "Superblock event notifications" + select WATCH_QUEUE + help + This option provides support for receiving superblock event + notifications. This makes use of the watch_queue API to + handle the notification buffer and provides the sb_notify() + system call to enable/disable watches. + + Events can include things like changing between R/W and R/O, EIO + generation, ENOSPC generation and EDQUOT generation. + source "fs/quota/Kconfig" source "fs/autofs/Kconfig"
fs/super.c +127 -0
148 lines not on this page · raw message
include/linux/fs.h +83 -0
99 lines not on this page · raw message
include/linux/syscalls.h +2 -0
@@ -1008,6 +1008,8 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,siginfo_t __user *info, unsigned int flags);asmlinkage long sys_pidfd_getfd (int pidfd,int fd,unsigned int flags); +asmlinkage long sys_watch_sb (int dfd,const char __user *path, +unsigned int at_flags,int watch_fd,int watch_id);/* * Architecture-specific system calls
include/uapi/asm-generic/unistd.h +3 -1
@@ -859,9 +859,11 @@ __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) __SYSCALL(__NR_faccessat2, sys_faccessat2)#define __NR_process_madvise 440 __SYSCALL(__NR_process_madvise, sys_process_madvise) +#define __NR_watch_sb 441 +__SYSCALL(__NR_watch_sb, sys_watch_sb)#undef __NR_syscalls -#define __NR_syscalls 441 +#define __NR_syscalls 442/* * 32 bit systems traditionally used different
include/uapi/linux/watch_queue.h +31 -1
@@ -14,7 +14,8 @@enum watch_notification_type {WATCH_TYPE_META =0 ,/* Special record */ WATCH_TYPE_KEY_NOTIFY =1 ,/* Key change event notification */ -WATCH_TYPE__NR =2 +WATCH_TYPE_SB_NOTIFY =2 , +WATCH_TYPE__NR =3 };enum watch_meta_notification_subtype {
@@ -101,4 +102,33 @@ struct key_notification { __u32 aux; /* Per-type auxiliary data */ }; +/* +* Type of superblock notification. +*/ +enum superblock_notification_type { +NOTIFY_SUPERBLOCK_READONLY =0 ,/* Filesystem toggled between R/O and R/W */ +NOTIFY_SUPERBLOCK_ERROR =1 ,/* Error in filesystem or blockdev */ +NOTIFY_SUPERBLOCK_EDQUOT =2 ,/* EDQUOT notification */ +NOTIFY_SUPERBLOCK_NETWORK =3 ,/* Network status change */ +}; + +#define NOTIFY_SUPERBLOCK_IS_NOW_RO WATCH_INFO_FLAG_0/* Superblock changed to R/O */ + +/* +* Superblock notification record. +* - watch.type = WATCH_TYPE_MOUNT_NOTIFY +* - watch.subtype = enum superblock_notification_subtype +*/ +struct superblock_notification { +struct watch_notification watch;/* WATCH_TYPE_SB_NOTIFY */ +__u64 sb_id;/* 64-bit superblock ID [fsinfo_ids::f_sb_id] */ +}; + +struct superblock_error_notification { +struct superblock_notification s;/* subtype = notify_superblock_error */ +__u32 error_number; +__u32 error_cookie; +char desc[0 ]; +}; +#endif /* _UAPI_LINUX_WATCH_QUEUE_H */
kernel/sys_ni.c +3 -0
@@ -51,6 +51,9 @@ COND_SYSCALL_COMPAT(io_pgetevents);COND_SYSCALL (io_uring_setup);COND_SYSCALL (io_uring_enter);COND_SYSCALL (io_uring_register); +COND_SYSCALL (fsinfo); +COND_SYSCALL (watch_mount); +COND_SYSCALL (watch_sb);/* fs/xattr.c */
Signature · 1 line
2.28.0
kernel test robot
build botRe: [PATCH RFC 4/7] vfs: Add superblock notifications
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Gabriel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[cannot apply to tip/x86/asm ext4/dev dhowells-fs/fscache-next v5.9 next-20201021] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Gabriel-Krisman-Bertazi/Superblock-notifications/20201021-031619 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5c7e3f3f5cbc31118914ceee969154582ad3aa6b config: microblaze-randconfig-r021-20201021 (attached as .config) compiler: microblaze-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/5cb688aebe8266750d6e77b560d7fcf24deab012
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Gabriel-Krisman-Bertazi/Superblock-notifications/20201021-031619 git checkout 5cb688aebe8266750d6e77b560d7fcf24deab012
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=microblaze
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> <stdin>:1529:2: warning: #warning syscall watch_sb not implemented [-Wcpp] -- >> <stdin>:1529:2: warning: #warning syscall watch_sb not implemented [-Wcpp] -- >> <stdin>:1529:2: warning: #warning syscall watch_sb not implemented [-Wcpp]
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH RFC 4/7] vfs: Add superblock notifications
In reply to Gabriel Krisman Bertazi[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Gabriel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[cannot apply to tip/x86/asm ext4/dev dhowells-fs/fscache-next v5.9 next-20201021] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Gabriel-Krisman-Bertazi/Superblock-notifications/20201021-031619 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5c7e3f3f5cbc31118914ceee969154582ad3aa6b config: s390-randconfig-r024-20201021 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 2eac8ce820e6c9fe51bf93b55cb8a781b8b9fc7c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/0day-ci/linux/commit/5cb688aebe8266750d6e77b560d7fcf24deab012
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Gabriel-Krisman-Bertazi/Superblock-notifications/20201021-031619 git checkout 5cb688aebe8266750d6e77b560d7fcf24deab012
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> <stdin>:1529:2: warning: syscall watch_sb not implemented [-W#warnings]
#warning syscall watch_sb not implemented
^
1 warning generated.
--
>> <stdin>:1529:2: warning: syscall watch_sb not implemented [-W#warnings]
#warning syscall watch_sb not implemented
^ 1 warning generated.
--
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:80:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:21:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
^
In file included from arch/s390/kernel/asm-offsets.c:11:
In file included from include/linux/kvm_host.h:32:
In file included from include/linux/kvm_para.h:5:
In file included from include/uapi/linux/kvm_para.h:36:
In file included from arch/s390/include/asm/kvm_para.h:25:
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:80:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
___constant_swab32(x) : \
^
include/uapi/linux/swab.h:22:12: note: expanded from macro '___constant_swab32'
(((__u32)(x) & (__u32)0xff000000UL) >> 24)))
^
In file included from arch/s390/kernel/asm-offsets.c:11:
In file included from include/linux/kvm_host.h:32:
In file included from include/linux/kvm_para.h:5:
In file included from include/uapi/linux/kvm_para.h:36:
In file included from arch/s390/include/asm/kvm_para.h:25:
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:80:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:120:12: note: expanded from macro '__swab32'
__fswab32(x))
^
In file included from arch/s390/kernel/asm-offsets.c:11:
In file included from include/linux/kvm_host.h:32:
In file included from include/linux/kvm_para.h:5:
In file included from include/uapi/linux/kvm_para.h:36:
In file included from arch/s390/include/asm/kvm_para.h:25:
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:80:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
20 warnings generated.
>> <stdin>:1529:2: warning: syscall watch_sb not implemented [-W#warnings]
#warning syscall watch_sb not implemented
^1 warning generated.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH 5/7 vfs: Include origin of the SB error notification
In reply to Gabriel Krisman BertaziWhen reporting a filesystem error, we really need to know where the error came from, therefore, include "function:line" information in the notification sent to userspace. There is no current users of notify_sb in the kernel, so there are no callers to update.
--- include/linux/fs.h | 10 ++++++++-- include/uapi/linux/watch_queue.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-)
include/linux/fs.h +8 -2
@@ -3516,12 +3516,14 @@ static inline void notify_sb(struct super_block *s,/** * notify_sb_error: Post superblock error notification. * @s: The superblock the notification is about. +* @function: function name reported as source of the warning. +* @line: source code line reported as source of the warning. * @error: The error number to be recorded. * @fmt: Formating string for extra information appended to the notification * @args: arguments for extra information string appended to the notification */ -static inline int notify_sb_error (struct super_block *s,int error, -const char *fmt,va_list *args) +static inline int notify_sb_error (struct super_block *s,const char *function, +int line,int error,const char *fmt,va_list *args) {#ifdef CONFIG_SB_NOTIFICATIONS if (unlikely (s->s_watchers)) {
@@ -3532,8 +3534,12 @@ static inline int notify_sb_error(struct super_block *s, int error, .s.sb_id = s->s_unique_id, .error_number = error, .error_cookie = 0, + .line = line, }; +memcpy (&n.function, function,SB_NOTIFICATION_FNAME_LEN ); + n.function[SB_NOTIFICATION_FNAME_LEN -1 ] ='\0' ; +post_sb_notification (s, &n.s, fmt, args); }#endif
include/uapi/linux/watch_queue.h +3 -0
@@ -114,6 +114,7 @@ enum superblock_notification_type {#define NOTIFY_SUPERBLOCK_IS_NOW_RO WATCH_INFO_FLAG_0/* Superblock changed to R/O */ +#define SB_NOTIFICATION_FNAME_LEN 30/* * Superblock notification record. * - watch.type = WATCH_TYPE_MOUNT_NOTIFY
@@ -128,6 +129,8 @@ struct superblock_error_notification {struct superblock_notification s;/* subtype = notify_superblock_error */ __u32 error_number;__u32 error_cookie; +char function[SB_NOTIFICATION_FNAME_LEN ]; +__u16 line;char desc[0 ]; };
Signature · 1 line
2.28.0
RFC PATCH 6/7 fs: Add more superblock error subtypes
In reply to Gabriel Krisman BertaziExpose new SB notification subtype for warnings, errors and general messages. This is modeled after the information exposed by ext4, but should be the same for other filesystems.
--- include/linux/fs.h | 118 +++++++++++++++++++++++++++++++ include/uapi/linux/watch_queue.h | 33 +++++++++ 2 files changed, 151 insertions(+)
include/linux/fs.h +118 -0
@@ -3513,6 +3513,28 @@ static inline void notify_sb(struct super_block *s,#endif } +/** +* notify_sb_msg: Post superblock message. +* @s: The superblock the notification is about. +* @fmt: Formating string for extra information appended to the notification +* @args: arguments for extra information string appended to the notification +*/ +static inline void notify_sb_msg (struct super_block *s,const char *fmt,va_list *args) +{ +#ifdef CONFIG_SB_NOTIFICATIONS +if (unlikely (s->s_watchers)) { +struct superblock_msg_notification n = { + .s.watch.type =WATCH_TYPE_SB_NOTIFY , + .s.watch.subtype =NOTIFY_SUPERBLOCK_MSG , + .s.watch.info =watch_sizeof (n), + .s.sb_id = s->s_unique_id, + }; + +post_sb_notification (s, &n.s, fmt, args); + } +#endif +} +/** * notify_sb_error: Post superblock error notification. * @s: The superblock the notification is about.
@@ -3546,6 +3568,35 @@ static inline int notify_sb_error(struct super_block *s, const char *function,return error; } +/** +* notify_sb_warning: Post superblock warning notification. +* @s: The superblock the notification is about. +* @function: function name reported as source of the warning. +* @line: source code line reported as source of the warning. +* @fmt: Formating string for extra information appended to the notification +* @args: arguments for extra information string appended to the notification +*/ +static inline void notify_sb_warning (struct super_block *s,const char *function, +int line,const char *fmt,va_list *args) +{ +#ifdef CONFIG_SB_NOTIFICATIONS +if (unlikely (s->s_watchers)) { +struct superblock_error_notification n = { + .s.watch.type =WATCH_TYPE_SB_NOTIFY , + .s.watch.subtype =NOTIFY_SUPERBLOCK_WARNING , + .s.watch.info =watch_sizeof (n), + .s.sb_id = s->s_unique_id, + .line = line, + }; + +memcpy (&n.function, function,SB_NOTIFICATION_FNAME_LEN ); + n.function[SB_NOTIFICATION_FNAME_LEN -1 ] ='\0' ; + +post_sb_notification (s, &n.s, fmt, args); + } +#endif +} +/** * notify_sb_EDQUOT: Post superblock quota overrun notification. * @s: The superblock the notification is about.
@@ -3567,4 +3618,71 @@ static inline int notify_sb_EQDUOT(struct super_block *s) return -EDQUOT; } +/** +* notify_sb_inode_error: Post superblock inode error notification. +* @s: The superblock the notification is about. +* @function: function name reported as source of the warning. +* @line: source code line reported as source of the warning. +* @error: The error number to be recorded. +* @ino: The inode number being accessed. +* @block: The block being accessed. +* @fmt: Formating string for extra information appended to the notification +* @args: arguments for extra information string appended to the notification +*/ +static inline int notify_sb_inode_error (struct super_block *s,const char *function, +int line,int error,u64 ino,u64 block, +const char *fmt,va_list *args) +{ +#ifdef CONFIG_SB_NOTIFICATIONS +if (unlikely (s->s_watchers)) { +struct superblock_inode_error_notification n = { + .s.watch.type =WATCH_TYPE_SB_NOTIFY , + .s.watch.subtype =NOTIFY_SUPERBLOCK_INODE_ERROR , + .s.watch.info =watch_sizeof (n), + .s.sb_id = s->s_unique_id, + .error_number = error, + .error_cookie =0 , + .line = line, + .inode = ino, + .block = block + }; + +memcpy (&n.function, function,SB_NOTIFICATION_FNAME_LEN ); + n.function[SB_NOTIFICATION_FNAME_LEN -1 ] ='\0' ; + +post_sb_notification (s, &n.s, fmt, args); + } +#endif +return error; +} + +/** +* notify_sb_inode_warning: Post superblock inode warning notification. +* @s: The superblock the notification is about. +* @function: function name reported as source of the warning. +* @line: source code line reported as source of the warning. +* @ino: The inode number being accessed. +* @block: The block being accessed. +* @fmt: Formating string for extra information appended to the notification +* @args: arguments for extra information string appended to the notification +*/ +static inline void notify_sb_inode_warning (struct super_block *s,const char *function, +int line,u64 ino,u64 block,const char *fmt, +va_list *args) +{ +#ifdef CONFIG_SB_NOTIFICATIONS +if (unlikely (s->s_watchers)) { +struct superblock_inode_warning_notification n = { + .s.watch.type =WATCH_TYPE_SB_NOTIFY , + .s.watch.subtype =NOTIFY_SUPERBLOCK_INODE_WARNING , + .s.watch.info =watch_sizeof (n), + .s.sb_id = s->s_unique_id, + .inode = ino, + .block = block + }; + +post_sb_notification (s, &n.s, fmt, args); + } +#endif +}#endif /* _LINUX_FS_H */
include/uapi/linux/watch_queue.h +33 -0
@@ -110,6 +110,10 @@ enum superblock_notification_type {NOTIFY_SUPERBLOCK_ERROR =1 ,/* Error in filesystem or blockdev */ NOTIFY_SUPERBLOCK_EDQUOT =2 ,/* EDQUOT notification */ NOTIFY_SUPERBLOCK_NETWORK =3 ,/* Network status change */ +NOTIFY_SUPERBLOCK_INODE_ERROR =4 ,/* Inode Error */ +NOTIFY_SUPERBLOCK_WARNING =5 ,/* Filesystem warning */ +NOTIFY_SUPERBLOCK_INODE_WARNING =6 ,/* Filesystem inode warning */ + NOTIFY_SUPERBLOCK_MSG = 7, /* Filesystem message */ };#define NOTIFY_SUPERBLOCK_IS_NOW_RO WATCH_INFO_FLAG_0/* Superblock changed to R/O */
@@ -134,4 +138,33 @@ struct superblock_error_notification { char desc[0]; }; +struct superblock_msg_notification { +struct superblock_notification s;/* subtype = notify_superblock_msg */ +char desc[0 ]; +}; + +struct superblock_warning_notification { +struct superblock_notification s;/* subtype = notify_superblock_warning */ +char function[SB_NOTIFICATION_FNAME_LEN ]; +__u16 line; +char desc[0 ]; +}; + +struct superblock_inode_error_notification { +struct superblock_notification s;/* subtype = notify_superblock_inode_error */ +__u32 error_number; +__u32 error_cookie; +char function[SB_NOTIFICATION_FNAME_LEN ]; +__u16 line; +__u64 inode; +__u64 block; +char desc[0 ]; +}; + +struct superblock_inode_warning_notification { +struct superblock_notification s;/* subtype = notify_superblock_inode_warning */ +__u64 inode; +__u64 block; +char desc[0 ]; +};#endif /* _UAPI_LINUX_WATCH_QUEUE_H */
Signature · 1 line
2.28.0
Theodore Y. Ts'o
maintainerRe: [PATCH RFC 6/7] fs: Add more superblock error subtypes
include/uapi/linux/watch_queue.h enum superblock_notification_type { · line 117
Quoted 13 lines · Gabriel Krisman Bertazi
include/uapi/linux/watch_queue.h +4
-0@@ -110,6 +110,10 @@ enum superblock_notification_type {NOTIFY_SUPERBLOCK_ERROR =1 ,/* Error in filesystem or blockdev */ NOTIFY_SUPERBLOCK_EDQUOT =2 ,/* EDQUOT notification */ NOTIFY_SUPERBLOCK_NETWORK =3 ,/* Network status change */ +NOTIFY_SUPERBLOCK_INODE_ERROR =4 ,/* Inode Error */ +NOTIFY_SUPERBLOCK_WARNING =5 ,/* Filesystem warning */ +NOTIFY_SUPERBLOCK_INODE_WARNING =6 ,/* Filesystem inode warning */ + NOTIFY_SUPERBLOCK_MSG = 7, /* Filesystem message */ };
Hmm, I wonder if this is the right break down. In ext4 we have ext4_error() and ext4_error_inode(), but that's just a convenience so that if there is an error number, we can log information relating to the inode. It's unclear if we need to break apart *_WARNING and *INODE_WARNING in the notification types. So I'd suggest dropping *_INODE_ERROR and *_INODE_WARNING and let those get subsumed into *_ERROR and *_WARNING. We can include the __64 for block and inode numbers for *_ERROR and _*WARNING, which can be non-zero if they are available for a particular notification.
I *do* thnk we should separate out file system error and blockdev warnings, however. So maybe NOTIFY_SUPERBLOCK_ERROR should be redifined to mean only "file system level error" and we should add a NOTIFY_SUPERBLOCK_EIO for an I/O errors coming from the block device. For that notification type, we can add a __u8 or __u32 containing the BLK_STS_* errors.
I suspect in the future we should also consider a new block device notification scheme, where we can provide more detailed information such as SCSI sense codes, etc. But that's a separable feature, I think.
Cheers,
- Ted
RFC PATCH 7/7 ext4: Implement SB error notification through watch_sb
In reply to Gabriel Krisman BertaziThis follows the same implementation of ext4 error reporting via dmesg, but expose that information via the new watch_queue notifications API.
--- fs/ext4/super.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
fs/ext4/super.c +24 -8
@@ -542,15 +542,17 @@ void __ext4_error(struct super_block *sb, const char *function,return ;trace_ext4_error (sb, function, line); +va_start (args, fmt);if (ext4_error_ratelimit (sb)) { -va_start (args, fmt); vaf.fmt = fmt; vaf.va = &args;printk (KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n" , sb->s_id, function, line, current->comm, &vaf); -va_end (args); } +notify_sb_error (sb, function, line, error, fmt, &args); +va_end (args); +save_error_info (sb, error,0 , block, function, line);ext4_handle_error (sb); }
@@ -566,8 +568,8 @@ void __ext4_error_inode(struct inode *inode, const char *function,return ;trace_ext4_error (inode->i_sb, function, line); +va_start (args, fmt);if (ext4_error_ratelimit (inode->i_sb)) { -va_start (args, fmt); vaf.fmt = fmt; vaf.va = &args;if (block)
@@ -580,8 +582,11 @@ void __ext4_error_inode(struct inode *inode, const char *function,"inode #%lu: comm %s: %pV\n" , inode->i_sb->s_id, function, line, inode->i_ino, current->comm, &vaf); -va_end (args); } +notify_sb_inode_error (inode->i_sb, function, line, error, inode->i_ino, block, + fmt, &args); +va_end (args); +save_error_info (inode->i_sb, error, inode->i_ino, block, function, line);ext4_handle_error (inode->i_sb);
@@ -600,11 +605,11 @@ void __ext4_error_file(struct file *file, const char *function,return ;trace_ext4_error (inode->i_sb, function, line); +va_start (args, fmt);if (ext4_error_ratelimit (inode->i_sb)) { path =file_path (file, pathname,sizeof (pathname));if (IS_ERR (path)) path ="(unknown)" ; -va_start (args, fmt); vaf.fmt = fmt; vaf.va = &args;if (block)
@@ -619,8 +624,11 @@ void __ext4_error_file(struct file *file, const char *function,"comm %s: path %s: %pV\n" , inode->i_sb->s_id, function, line, inode->i_ino, current->comm, path, &vaf); -va_end (args); } +notify_sb_inode_error (inode->i_sb, function, line,EFSCORRUPTED , + inode->i_ino, block, fmt, &args); +va_end (args); +save_error_info (inode->i_sb,EFSCORRUPTED , inode->i_ino, block, function, line);ext4_handle_error (inode->i_sb);
@@ -690,6 +698,8 @@ void __ext4_std_error(struct super_block *sb, const char *function, sb->s_id, function, line, errstr); } +notify_sb_error (sb, function, line, errno, errstr,NULL ); +save_error_info (sb, -errno,0 ,0 , function, line);ext4_handle_error (sb); }
@@ -719,6 +729,7 @@ void __ext4_abort(struct super_block *sb, const char *function, vaf.va = &args;printk (KERN_CRIT "EXT4-fs error (device %s): %s:%d: %pV\n" , sb->s_id, function, line, &vaf); +notify_sb_error (sb, function, line, error, fmt, &args);va_end (args);if (sb_rdonly (sb) ==0 ) {
@@ -752,6 +763,7 @@ void __ext4_msg(struct super_block *sb, vaf.fmt = fmt; vaf.va = &args;printk ("%sEXT4-fs (%s): %pV\n" , prefix, sb->s_id, &vaf); +notify_sb_msg (sb, fmt, &args);va_end (args); }
@@ -776,6 +788,7 @@ void __ext4_warning(struct super_block *sb, const char *function, vaf.va = &args;printk (KERN_WARNING "EXT4-fs warning (device %s): %s:%d: %pV\n" , sb->s_id, function, line, &vaf); +notify_sb_warning (sb, function, line, fmt, &args);va_end (args); }
@@ -794,6 +807,7 @@ void __ext4_warning_inode(const struct inode *inode, const char *function,printk (KERN_WARNING "EXT4-fs warning (device %s): %s:%d: " "inode #%lu: comm %s: %pV\n" , inode->i_sb->s_id, function, line, inode->i_ino, current->comm, &vaf); +notify_sb_inode_warning (inode->i_sb, function, line, inode->i_ino,0 , fmt, &args);va_end (args); }
@@ -813,8 +827,8 @@ __acquires(bitlock)trace_ext4_error (sb, function, line);__save_error_info (sb,EFSCORRUPTED , ino, block, function, line); +va_start (args, fmt);if (ext4_error_ratelimit (sb)) { -va_start (args, fmt); vaf.fmt = fmt; vaf.va = &args; printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u, ",
@@ -825,8 +839,10 @@ __acquires(bitlock)printk (KERN_CONT "block %llu:" , (unsigned long long ) block);printk (KERN_CONT "%pV\n" , &vaf); -va_end (args); } +notify_sb_inode_error (sb, function, line,EFSCORRUPTED , + ino, block, fmt, &args); +va_end (args);if (test_opt (sb,WARN_ON_ERROR ))WARN_ON_ONCE (1 );
Signature · 1 line
2.28.0