This commit makes kdbus driver working with kernel 4.14.
It also enabled compilation of the driver if enabled in config.
The list of changes needed to make it compile with kernel 4.14:
- Add missing includes for <linux/cred.h>
- put inode_lock()/inode_unlock() in place of explicit mutex locking
- replace CURRENT_TIME with proper call to current_time()
- replace PAGE_CACHE_* with PAGE_*
- replace GFP_TEMPORARY with GFP_KERNEL
- use kvecs for kernel memory, iovec for user memory instead of only iovec
for both
- fix usage of task_cgroup_path()
- replace GROUP_AT usage with 'gid' field dereference
- add 0 as an argument to init_name_hash
- add 0 as flags as an argument to vfs_iter_write
- replace __vfs_read with kernel_read to allow compilation into module
Change-Id: Ifed3a6d3a37082a900a64316af1c8a21ab30e84e
Origin: commit:
846051292431cc81adb852c2b0cbbfddac4a3d48
Signed-off-by: Adrian Szyndela <adrian.s@samsung.com>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o
obj-$(CONFIG_IPC_NS) += namespace.o
obj-$(CONFIG_POSIX_MQUEUE_SYSCTL) += mq_sysctl.o
-#obj-$(CONFIG_KDBUS) += kdbus/
+obj-$(CONFIG_KDBUS) += kdbus/
* your option) any later version.
*/
+#include <linux/cred.h>
#include <linux/fs.h>
#include <linux/hashtable.h>
#include <linux/init.h>
* your option) any later version.
*/
+#include <linux/cred.h>
#include <linux/fs.h>
#include <linux/idr.h>
#include <linux/init.h>
* your option) any later version.
*/
+#include <linux/cred.h>
#include <linux/fs.h>
#include <linux/idr.h>
#include <linux/init.h>
loff_t ret;
/* protect f_off against fop_iterate */
- mutex_lock(&inode->i_mutex);
+ inode_lock(inode);
ret = generic_file_llseek(file, offset, whence);
- mutex_unlock(&inode->i_mutex);
+ inode_unlock(inode);
return ret;
}
inode->i_private = kdbus_node_ref(node);
inode->i_mapping->a_ops = &empty_aops;
inode->i_mode = node->mode & S_IALLUGO;
- inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
+ inode->i_atime = inode->i_ctime = inode->i_mtime = current_time(inode);
inode->i_uid = node->uid;
inode->i_gid = node->gid;
struct inode *inode;
int ret;
- sb->s_blocksize = PAGE_CACHE_SIZE;
- sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
+ sb->s_blocksize = PAGE_SIZE;
+ sb->s_blocksize_bits = PAGE_SHIFT;
sb->s_magic = KDBUS_SUPER_MAGIC;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_op = &fs_super_sops;
return 0;
}
- fds = kmalloc_array(n_fds, sizeof(*fds), GFP_TEMPORARY);
+ fds = kmalloc_array(n_fds, sizeof(*fds), GFP_KERNEL);
n_fds = 0;
if (!fds)
return -ENOMEM;
if (msg->flags & KDBUS_MSG_EXPECT_REPLY) {
/* if you expect a reply, you must specify a timeout */
- if (msg->timeout_ns == 0)
+ if (msg->timeout_ns == 0 || !msg->cookie)
return -EINVAL;
/* signals cannot have replies */
if (msg->flags & KDBUS_MSG_SIGNAL)
n_parts += reserved_parts;
staging = kzalloc(sizeof(*staging) + n_parts * sizeof(*staging->parts) +
- msg_extra_size, GFP_TEMPORARY);
+ msg_extra_size, GFP_KERNEL);
if (!staging)
return ERR_PTR(-ENOMEM);
struct iovec *v;
u64 attach, msg_size;
int ret;
+ size_t kvec_parts_count, size_before_payload = 0;
/*
* Step 1:
++v;
}
+ kvec_parts_count = v - staging->parts;
+
/* ... payload iovecs are already filled in ... */
/* compute overall size and fill in padding after payload */
WARN_ON(kdbus_pool_slice_size(slice) != size);
- ret = kdbus_pool_slice_copy_iovec(slice, 0, staging->parts,
- staging->n_parts, size);
+ {
+ ulong count_parts;
+ for (count_parts = 0; count_parts < kvec_parts_count; count_parts++)
+ size_before_payload += staging->parts[count_parts].iov_len;
+ }
+
+ ret = kdbus_pool_slice_copy_kvec(slice, 0, (struct kvec *)staging->parts,
+ kvec_parts_count, size_before_payload);
if (ret < 0)
goto error;
+ for (; kvec_parts_count < staging->n_parts; kvec_parts_count++) {
+ struct iovec *part = &staging->parts[kvec_parts_count];
+ if (part->iov_base != zeros)
+ ret = kdbus_pool_slice_copy_iovec(slice, size_before_payload,
+ part, 1, part->iov_len);
+ else
+ ret = kdbus_pool_slice_copy_kvec(slice, size_before_payload,
+ (struct kvec *)&part, 1, part->iov_len);
+ if (ret < 0)
+ goto error;
+ size_before_payload += part->iov_len;
+ }
+
/* all done, return slice to caller */
goto exit;
{
#ifdef CONFIG_CGROUPS
void *page;
- char *s;
- page = (void *)__get_free_page(GFP_TEMPORARY);
+ page = (void *)__get_free_page(GFP_KERNEL);
if (!page)
return -ENOMEM;
- s = task_cgroup_path(current, page, PAGE_SIZE);
- if (s) {
- mp->cgroup = kstrdup(s, GFP_KERNEL);
+ if (task_cgroup_path(current, page, PAGE_SIZE) < PAGE_SIZE) {
+ mp->cgroup = kstrdup(page, GFP_KERNEL);
if (!mp->cgroup) {
free_page((unsigned long)page);
return -ENOMEM;
item = kdbus_write_head(&items, KDBUS_ITEM_AUXGROUPS,
info->ngroups * sizeof(u64));
for (i = 0; i < info->ngroups; ++i)
- item->data64[i] = from_kgid_munged(user_ns,
- GROUP_AT(info, i));
+ item->data64[i] = from_kgid_munged(user_ns, info->gid[i]);
}
if (staging->mp && (staging->mask & KDBUS_ATTACH_TID_COMM))
get_fs_root(current->fs, &p);
if (path_equal(&p, &conn->root_path)) {
- staging.exe = (void *)__get_free_page(GFP_TEMPORARY);
+ staging.exe = (void *)__get_free_page(GFP_KERNEL);
if (!staging.exe) {
path_put(&p);
ret = -ENOMEM;
* your option) any later version.
*/
+#include <linux/cred.h>
#include <linux/ctype.h>
#include <linux/fs.h>
#include <linux/hash.h>
* your option) any later version.
*/
+#include <linux/cred.h>
#include <linux/dcache.h>
#include <linux/fs.h>
#include <linux/init.h>
static unsigned int kdbus_strnhash(const char *str, size_t len)
{
- unsigned long hash = init_name_hash();
+ unsigned long hash = init_name_hash(0);
while (len--)
hash = partial_name_hash(*str++, hash);
}
for (i = 0; i < cred->group_info->ngroups; i++) {
- kgid_t gid = GROUP_AT(cred->group_info, i);
+ kgid_t gid = cred->group_info->gid[i];
if (gid_eq(gid, a->gid)) {
highest = a->access;
off += slice->off;
iov_iter_init(&iter, WRITE, iov, iov_len, total_len);
- len = vfs_iter_write(slice->pool->f, &iter, &off);
+ len = vfs_iter_write(slice->pool->f, &iter, &off, 0);
return (len >= 0 && len != total_len) ? -EFAULT : len;
}
old_fs = get_fs();
set_fs(get_ds());
- len = vfs_iter_write(slice->pool->f, &iter, &off);
+ len = vfs_iter_write(slice->pool->f, &iter, &off, 0);
set_fs(old_fs);
return (len >= 0 && len != total_len) ? -EFAULT : len;
WARN_ON(slice_src->free || slice_dst->free))
return -EINVAL;
- mutex_lock(&i_dst->i_mutex);
+ inode_lock(i_dst);
old_fs = get_fs();
set_fs(get_ds());
while (len > 0) {
void *fsdata;
long status;
- page_off = off_dst & (PAGE_CACHE_SIZE - 1);
+ page_off = off_dst & (PAGE_SIZE - 1);
copy_len = min_t(unsigned long,
- PAGE_CACHE_SIZE - page_off, len);
+ PAGE_SIZE - page_off, len);
status = aops->write_begin(f_dst, mapping_dst, off_dst,
copy_len, 0, &page, &fsdata);
}
kaddr = (char __force __user *)kmap(page) + page_off;
- n_read = __vfs_read(f_src, kaddr, copy_len, &off_src);
+ n_read = kernel_read(f_src, kaddr, copy_len, &off_src);
kunmap(page);
mark_page_accessed(page);
flush_dcache_page(page);
len -= copy_len;
}
set_fs(old_fs);
- mutex_unlock(&i_dst->i_mutex);
+ inode_unlock(i_dst);
return ret;
}
*/
static inline unsigned int kdbus_strhash(const char *str)
{
- unsigned long hash = init_name_hash();
+ unsigned long hash = init_name_hash(0);
while (*str)
hash = partial_name_hash(*str++, hash);
# Makefile for Linux samples code
obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \
- hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \
+ hw_breakpoint/ kfifo/ kdb/ kdbus/ hidraw/ rpmsg/ seccomp/ \
configfs/ connector/ v4l/ trace_printk/ \
vfio-mdev/ statx/ qmi/