Re: [PATCH] media: cxusb, dib0700: ignore XC2028_I2C_FLUSH

2018-01-24 Thread Enrico Mioso

Thank you very very much for the fix.
You did really make my everyday experience better.



On Wed, 24 Jan 2018, Mauro Carvalho Chehab wrote:


Date: Wed, 24 Jan 2018 12:05:24
From: Mauro Carvalho Chehab 
To: Enrico Mioso ,
Linux Media Mailing List ,
Jonathan Corbet 
Cc: Mauro Carvalho Chehab ,
Mauro Carvalho Chehab ,
Linux Doc Mailing List ,
Michael Krufky , Sean Young ,
Hans Verkuil ,
Andrey Konovalov ,
Piotr Oleszczyk ,
Alexey Dobriyan 
Subject: [PATCH] media: cxusb, dib0700: ignore XC2028_I2C_FLUSH

The XC2028_I2C_FLUSH only needs to be implemented on a few
devices. Others can safely ignore it.

That prevents filling the dmesg with lots of messages like:

dib0700: stk7700ph_xc3028_callback: unknown command 2, arg 0

Reported-by: Enrico Mioso 
Signed-off-by: Mauro Carvalho Chehab 
---
drivers/media/usb/dvb-usb/cxusb.c   | 2 ++
drivers/media/usb/dvb-usb/dib0700_devices.c | 1 +
2 files changed, 3 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 37dea0adc695..cfe86b4864b3 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -677,6 +677,8 @@ static int dvico_bluebird_xc2028_callback(void *ptr, int 
component,
case XC2028_RESET_CLK:
deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
break;
+   case XC2028_I2C_FLUSH:
+   break;
default:
deb_info("%s: unknown command %d, arg %d\n", __func__,
 command, arg);
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 366b05529915..a9968fb1e8e4 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -430,6 +430,7 @@ static int stk7700ph_xc3028_callback(void *ptr, int 
component,
state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
break;
case XC2028_RESET_CLK:
+   case XC2028_I2C_FLUSH:
break;
default:
err("%s: unknown command %d, arg %d\n", __func__,
--
2.14.3



--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 07/15] initramfs: split header layout information from parsing function

2018-01-24 Thread Taras Kondratiuk
Header parsing has hardcoded assumption about header field size and
layout. It is hard to modify the function to parse a new format.

Move information about size and layout into a data structure to
make parsing code more generic and simplify adding a new format.
This also removes some magic numbers.

Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 122 +--
 1 file changed, 92 insertions(+), 30 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index b3d39c8793be..7f0bbfde94e3 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -150,39 +150,100 @@ static void __init dir_utime(void)
}
 }
 
-static __initdata time64_t mtime;
-
 /* cpio header parsing */
-
-static __initdata unsigned long ino, major, minor, nlink;
+static __initdata time64_t mtime;
+static __initdata u32 ino, major, minor, nlink, rmajor, rminor;
 static __initdata umode_t mode;
-static __initdata unsigned long body_len, name_len;
+static __initdata u32 body_len, name_len;
 static __initdata uid_t uid;
 static __initdata gid_t gid;
-static __initdata unsigned rdev;
+static __initdata u32 mode_u32;
+
+struct cpio_hdr_field {
+   size_t offset;
+   size_t size;
+   void *out;
+   size_t out_size;
+   const char *name;
+};
+
+#define HDR_FIELD(type, field, variable) \
+   { .offset = offsetof(type, field) + \
+ BUILD_BUG_ON_ZERO(sizeof(*(variable))*2 < FIELD_SIZEOF(type, field)),\
+ .size = FIELD_SIZEOF(type, field), \
+ .out = variable, \
+ .out_size = sizeof(*(variable)), \
+ .name = #field }
+
+#define NEWC_FIELD(field, variable) \
+   HDR_FIELD(struct cpio_newc_header, field, variable)
+
+#define CPIO_MAX_HEADER_SIZE sizeof(struct cpio_newc_header)
+#define CPIO_MAX_FIELD_SIZE 8
+#define CPIO_MAGIC_SIZE 6
+
+struct cpio_newc_header {
+   charc_ino[8];
+   charc_mode[8];
+   charc_uid[8];
+   charc_gid[8];
+   charc_nlink[8];
+   charc_mtime[8];
+   charc_filesize[8];
+   charc_devmajor[8];
+   charc_devminor[8];
+   charc_rdevmajor[8];
+   charc_rdevminor[8];
+   charc_namesize[8];
+   charc_check[8];
+};
+
+static struct cpio_hdr_field cpio_newc_header_info[] __initdata = {
+   NEWC_FIELD(c_ino, ),
+   NEWC_FIELD(c_mode, _u32),
+   NEWC_FIELD(c_uid, ),
+   NEWC_FIELD(c_gid, ),
+   NEWC_FIELD(c_nlink, ),
+   NEWC_FIELD(c_mtime, ),
+   NEWC_FIELD(c_filesize, _len),
+   NEWC_FIELD(c_devmajor, ),
+   NEWC_FIELD(c_devminor, ),
+   NEWC_FIELD(c_rdevmajor, ),
+   NEWC_FIELD(c_rdevminor, ),
+   NEWC_FIELD(c_namesize, _len),
+   { 0 },
+};
 
 static void __init parse_header(char *s)
 {
-   unsigned long parsed[12];
-   char buf[9];
-   int i;
-
-   buf[8] = '\0';
-   for (i = 0; i < 12; i++, s += 8) {
-   memcpy(buf, s, 8);
-   parsed[i] = simple_strtoul(buf, NULL, 16);
+   char buf[CPIO_MAX_FIELD_SIZE + 1];
+   struct cpio_hdr_field *field = cpio_newc_header_info;
+
+   while (field->size) {
+   int ret = 0;
+
+   memcpy(buf, s + field->offset, field->size);
+   buf[field->size] = '\0';
+   switch (field->out_size) {
+   case sizeof(u32):
+   ret = kstrtou32(buf, 16, field->out);
+   pr_debug("cpio field %s: %u, buf: %s\n",
+field->name, *(u32 *)field->out, buf);
+   break;
+   case sizeof(u64):
+   ret = kstrtou64(buf, 16, field->out);
+   pr_debug("cpio field %s: %llu, buf: %s\n",
+field->name, *(u64 *)field->out, buf);
+   break;
+   default:
+   BUG_ON(1);
+   }
+
+   if (ret)
+   pr_err("invalid cpio header field (%d)", ret);
+   field++;
}
-   ino = parsed[0];
-   mode = parsed[1];
-   uid = parsed[2];
-   gid = parsed[3];
-   nlink = parsed[4];
-   mtime = parsed[5]; /* breaks in y2106 */
-   body_len = parsed[6];
-   major = parsed[7];
-   minor = parsed[8];
-   rdev = new_encode_dev(MKDEV(parsed[9], parsed[10]));
-   name_len = parsed[11];
+   mode = mode_u32;
 }
 
 /* FSM */
@@ -234,7 +295,7 @@ static __initdata char *header_buf, *symlink_buf, *name_buf;
 
 static int __init do_start(void)
 {
-   read_into(header_buf, 6, do_format);
+   read_into(header_buf, CPIO_MAGIC_SIZE, do_format);
return 0;
 }
 
@@ -254,15 +315,15 @@ static int __init do_collect(void)
 
 static int __init do_format(void)
 {
-   if (memcmp(collected, "070707", 6)==0) {
+   if (memcmp(collected, "070707", CPIO_MAGIC_SIZE) == 0) {
error("incorrect cpio 

[PATCH v2 02/15] initramfs: replace states with function pointers

2018-01-24 Thread Taras Kondratiuk
Currently the FSM states are mapped directly to function pointers. Extra
level of intirection is not needed and makes navigation over the code
harder. One can't jump between states directly when browsing code (e.g.
with cscope). Need to go through actions[] array each time.

Replace states with their action function pointers. No behaviour change.

Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 73 +---
 1 file changed, 32 insertions(+), 41 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 7e99a0038942..49cd2681a26f 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -187,16 +187,17 @@ static void __init parse_header(char *s)
 
 /* FSM */
 
-static __initdata enum state {
-   Start,
-   Collect,
-   GotHeader,
-   SkipIt,
-   GotName,
-   CopyFile,
-   GotSymlink,
-   Reset
-} state, next_state;
+static int __init do_start(void);
+static int __init do_collect(void);
+static int __init do_header(void);
+static int __init do_skip(void);
+static int __init do_name(void);
+static int __init do_copy(void);
+static int __init do_symlink(void);
+static int __init do_reset(void);
+
+typedef int (*fsm_state_t)(void);
+static __initdata fsm_state_t state, next_state;
 
 static __initdata char *victim;
 static unsigned long byte_count __initdata;
@@ -214,7 +215,7 @@ static __initdata char *collected;
 static long remains __initdata;
 static __initdata char *collect;
 
-static void __init read_into(char *buf, unsigned size, enum state next)
+static void __init read_into(char *buf, unsigned size, fsm_state_t next)
 {
if (byte_count >= size) {
collected = victim;
@@ -224,7 +225,7 @@ static void __init read_into(char *buf, unsigned size, enum 
state next)
collect = collected = buf;
remains = size;
next_state = next;
-   state = Collect;
+   state = do_collect;
}
 }
 
@@ -232,7 +233,7 @@ static __initdata char *header_buf, *symlink_buf, *name_buf;
 
 static int __init do_start(void)
 {
-   read_into(header_buf, 110, GotHeader);
+   read_into(header_buf, 110, do_header);
return 0;
 }
 
@@ -263,7 +264,7 @@ static int __init do_header(void)
parse_header(collected);
next_header = this_header + N_ALIGN(name_len) + body_len;
next_header = (next_header + 3) & ~3;
-   state = SkipIt;
+   state = do_skip;
if (name_len <= 0 || name_len > PATH_MAX)
return 0;
if (S_ISLNK(mode)) {
@@ -271,12 +272,12 @@ static int __init do_header(void)
return 0;
collect = collected = symlink_buf;
remains = N_ALIGN(name_len) + body_len;
-   next_state = GotSymlink;
-   state = Collect;
+   next_state = do_symlink;
+   state = do_collect;
return 0;
}
if (S_ISREG(mode) || !body_len)
-   read_into(name_buf, N_ALIGN(name_len), GotName);
+   read_into(name_buf, N_ALIGN(name_len), do_name);
return 0;
 }
 
@@ -327,8 +328,8 @@ static __initdata int wfd;
 
 static int __init do_name(void)
 {
-   state = SkipIt;
-   next_state = Reset;
+   state = do_skip;
+   next_state = do_reset;
if (strcmp(collected, "TRAILER!!!") == 0) {
free_hash();
return 0;
@@ -348,7 +349,7 @@ static int __init do_name(void)
if (body_len)
sys_ftruncate(wfd, body_len);
vcollected = kstrdup(collected, GFP_KERNEL);
-   state = CopyFile;
+   state = do_copy;
}
}
} else if (S_ISDIR(mode)) {
@@ -377,7 +378,7 @@ static int __init do_copy(void)
do_utime(vcollected, mtime);
kfree(vcollected);
eat(body_len);
-   state = SkipIt;
+   state = do_skip;
return 0;
} else {
if (xwrite(wfd, victim, byte_count) != byte_count)
@@ -395,29 +396,19 @@ static int __init do_symlink(void)
sys_symlink(collected + N_ALIGN(name_len), collected);
sys_lchown(collected, uid, gid);
do_utime(collected, mtime);
-   state = SkipIt;
-   next_state = Reset;
+   state = do_skip;
+   next_state = do_reset;
return 0;
 }
 
-static __initdata int (*actions[])(void) = {
-   [Start] = do_start,
-   [Collect]   = do_collect,
-   [GotHeader] = do_header,
-   [SkipIt]= do_skip,
-   [GotName]   = do_name,
-   [CopyFile]  = do_copy,
-   [GotSymlink]= do_symlink,
-   [Reset] = do_reset,
-};
-
 static long __init write_buffer(char *buf, unsigned long len)
 {

[PATCH v2 14/15] selinux: allow setxattr on rootfs so initramfs code can set them

2018-01-24 Thread Taras Kondratiuk
From: Victor Kamensky 

initramfs code supporting extended cpio format have ability to
fill extended attributes from cpio archive, but if SELinux enabled
and security server is not initialized yet, selinux callback would
refuse setxattr made by initramfs code.

Solution enable SBLABEL_MNT on rootfs even if secrurity server is
not initialized yet.

Signed-off-by: Victor Kamensky 
---
 security/selinux/hooks.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 8644d864e3c1..f3fe65589f02 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -706,6 +706,18 @@ static int selinux_set_mnt_opts(struct super_block *sb,
 
if (!ss_initialized) {
if (!num_opts) {
+   /*
+* Special handling for rootfs. Is genfs but supports
+* setting SELinux context on in-core inodes.
+*
+* Chicken and egg problem: policy may reside in rootfs
+* but for initramfs code to fill in attributes, it
+* needs selinux to allow that.
+*/
+   if (!strncmp(sb->s_type->name, "rootfs",
+sizeof("rootfs")))
+   sbsec->flags |= SBLABEL_MNT;
+
/* Defer initialization until selinux_complete_init,
   after the initial policy is loaded and the security
   server is ready to handle calls. */
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 04/15] initramfs: remove unnecessary symlinks processing shortcut

2018-01-24 Thread Taras Kondratiuk
Special handling of symlinks in do_header() assumes that name and body
entries are sequential and reads them together. This shortcut has no
real performance benefits, but it complicates changes to the state
machine.

Make handling of symlinks more similar to a regular files. Store name
in name_buf and destination in symlink_buf.

Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index b6ee675e5cdb..d0ab7ad6ac05 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -266,16 +266,7 @@ static int __init do_header(void)
state = do_skip;
if (name_len <= 0 || name_len > PATH_MAX)
return 0;
-   if (S_ISLNK(mode)) {
-   if (body_len > PATH_MAX)
-   return 0;
-   collect = collected = symlink_buf;
-   remains = N_ALIGN(name_len) + body_len;
-   next_state = do_symlink;
-   state = do_collect;
-   return 0;
-   }
-   if (S_ISREG(mode) || !body_len)
+   if (S_ISREG(mode) || S_ISLNK(mode) || !body_len)
read_into(name_buf, N_ALIGN(name_len), do_name);
return 0;
 }
@@ -372,6 +363,11 @@ static int __init do_name(void)
sys_chmod(collected, mode);
do_utime(collected, mtime);
}
+   } else if (S_ISLNK(mode)) {
+   if (body_len > PATH_MAX)
+   return 0;
+   memcpy_optional(name_buf, collected, N_ALIGN(name_len));
+   read_into(symlink_buf, body_len, do_symlink);
}
return 0;
 }
@@ -397,11 +393,12 @@ static int __init do_copy(void)
 
 static int __init do_symlink(void)
 {
-   collected[N_ALIGN(name_len) + body_len] = '\0';
-   clean_path(collected, 0);
-   sys_symlink(collected + N_ALIGN(name_len), collected);
-   sys_lchown(collected, uid, gid);
-   do_utime(collected, mtime);
+   memcpy_optional(symlink_buf, collected, body_len);
+   symlink_buf[body_len] = '\0';
+   clean_path(name_buf, 0);
+   sys_symlink(symlink_buf, name_buf);
+   sys_lchown(name_buf, uid, gid);
+   do_utime(name_buf, mtime);
state = do_skip;
next_state = do_reset;
return 0;
@@ -453,7 +450,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned 
long len)
static __initdata char msg_buf[64];
 
header_buf = kmalloc(110, GFP_KERNEL);
-   symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
+   symlink_buf = kmalloc(PATH_MAX + 1, GFP_KERNEL);
name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
 
if (!header_buf || !symlink_buf || !name_buf)
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 05/15] initramfs: move files creation into separate state

2018-01-24 Thread Taras Kondratiuk
Move most of the file creation logic into a separate state. This splits
collection of data stage from data processing and makes it easier to add
additional states for a new archive format.

Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 52 ++--
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index d0ab7ad6ac05..2d5920c094e0 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -192,6 +192,7 @@ static int __init do_collect(void);
 static int __init do_header(void);
 static int __init do_skip(void);
 static int __init do_name(void);
+static int __init do_create(void);
 static int __init do_copy(void);
 static int __init do_symlink(void);
 static int __init do_reset(void);
@@ -292,12 +293,12 @@ static int __init do_reset(void)
return 1;
 }
 
-static int __init maybe_link(void)
+static int __init maybe_link(char *name)
 {
if (nlink >= 2) {
-   char *old = find_link(major, minor, ino, mode, collected);
+   char *old = find_link(major, minor, ino, mode, name);
if (old)
-   return (sys_link(old, collected) < 0) ? -1 : 1;
+   return (sys_link(old, name) < 0) ? -1 : 1;
}
return 0;
 }
@@ -321,52 +322,59 @@ static void *memcpy_optional(void *dest, const void *src, 
size_t n)
return dest;
 }
 
-static __initdata int wfd;
-
 static int __init do_name(void)
 {
-   state = do_skip;
-   next_state = do_reset;
if (strcmp(collected, "TRAILER!!!") == 0) {
+   state = do_skip;
+   next_state = do_reset;
free_hash();
return 0;
}
-   clean_path(collected, mode);
+   memcpy_optional(name_buf, collected, N_ALIGN(name_len));
+   state = do_create;
+   return 0;
+}
+
+
+static __initdata int wfd;
+
+static int __init do_create(void)
+{
+   state = do_skip;
+   next_state = do_reset;
+   clean_path(name_buf, mode);
if (S_ISREG(mode)) {
-   int ml = maybe_link();
+   int ml = maybe_link(name_buf);
if (ml >= 0) {
int openflags = O_WRONLY|O_CREAT;
if (ml != 1)
openflags |= O_TRUNC;
-   wfd = sys_open(collected, openflags, mode);
+   wfd = sys_open(name_buf, openflags, mode);
 
if (wfd >= 0) {
sys_fchown(wfd, uid, gid);
sys_fchmod(wfd, mode);
if (body_len)
sys_ftruncate(wfd, body_len);
-   memcpy_optional(name_buf, collected,
-   N_ALIGN(name_len));
state = do_copy;
}
}
} else if (S_ISDIR(mode)) {
-   sys_mkdir(collected, mode);
-   sys_chown(collected, uid, gid);
-   sys_chmod(collected, mode);
-   dir_add(collected, mtime);
+   sys_mkdir(name_buf, mode);
+   sys_chown(name_buf, uid, gid);
+   sys_chmod(name_buf, mode);
+   dir_add(name_buf, mtime);
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
   S_ISFIFO(mode) || S_ISSOCK(mode)) {
-   if (maybe_link() == 0) {
-   sys_mknod(collected, mode, rdev);
-   sys_chown(collected, uid, gid);
-   sys_chmod(collected, mode);
-   do_utime(collected, mtime);
+   if (maybe_link(name_buf) == 0) {
+   sys_mknod(name_buf, mode, rdev);
+   sys_chown(name_buf, uid, gid);
+   sys_chmod(name_buf, mode);
+   do_utime(name_buf, mtime);
}
} else if (S_ISLNK(mode)) {
if (body_len > PATH_MAX)
return 0;
-   memcpy_optional(name_buf, collected, N_ALIGN(name_len));
read_into(symlink_buf, body_len, do_symlink);
}
return 0;
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 15/15] selinux: delay sid population for rootfs till init is complete

2018-01-24 Thread Taras Kondratiuk
From: Victor Kamensky 

With initramfs cpio format that supports extended attributes
we need to skip sid population on sys_lsetxattr call from
initramfs for rootfs if security server is not initialized yet.

Otherwise callback in selinux_inode_post_setxattr will try to
translate give security.selinux label into sid context and since
security server is not available yet inode will receive default
sid (typically kernel_t). Note that in the same time proper
label will be stored in inode xattrs. Later, since inode sid
would be already populated system will never look back at
actual xattrs. But if we skip sid population for rootfs and
we have policy that direct use of xattrs for rootfs, proper
sid will be filled in from extended attributes one node is
accessed and server is initialized.

Note new DELAYAFTERINIT_MNT super block flag is introduced
to only mark rootfs for such behavior. For other types of
tmpfs original logic is still used.

Signed-off-by: Victor Kamensky 
---
 security/selinux/hooks.c| 9 -
 security/selinux/include/security.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f3fe65589f02..bb25268f734e 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -716,7 +716,7 @@ static int selinux_set_mnt_opts(struct super_block *sb,
 */
if (!strncmp(sb->s_type->name, "rootfs",
 sizeof("rootfs")))
-   sbsec->flags |= SBLABEL_MNT;
+   sbsec->flags |= SBLABEL_MNT|DELAYAFTERINIT_MNT;
 
/* Defer initialization until selinux_complete_init,
   after the initial policy is loaded and the security
@@ -3253,6 +3253,7 @@ static void selinux_inode_post_setxattr(struct dentry 
*dentry, const char *name,
 {
struct inode *inode = d_backing_inode(dentry);
struct inode_security_struct *isec;
+   struct superblock_security_struct *sbsec;
u32 newsid;
int rc;
 
@@ -3261,6 +3262,12 @@ static void selinux_inode_post_setxattr(struct dentry 
*dentry, const char *name,
return;
}
 
+   if (!ss_initialized) {
+   sbsec = inode->i_sb->s_security;
+   if (sbsec->flags & DELAYAFTERINIT_MNT)
+   return;
+   }
+
rc = security_context_to_sid_force(value, size, );
if (rc) {
printk(KERN_ERR "SELinux:  unable to map context to SID"
diff --git a/security/selinux/include/security.h 
b/security/selinux/include/security.h
index 02f0412d42f2..585acfd6cbcf 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -52,6 +52,7 @@
 #define ROOTCONTEXT_MNT0x04
 #define DEFCONTEXT_MNT 0x08
 #define SBLABEL_MNT0x10
+#define DELAYAFTERINIT_MNT 0x20
 /* Non-mount related flags */
 #define SE_SBINITIALIZED   0x0100
 #define SE_SBPROC  0x0200
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 01/15] Documentation: add newcx initramfs format description

2018-01-24 Thread Taras Kondratiuk
Many of the Linux security/integrity features are dependent on file
metadata, stored as extended attributes (xattrs), for making decisions.
These features need to be initialized during initcall and enabled as
early as possible for complete security coverage.

Initramfs (tmpfs) supports xattrs, but newc CPIO archive format does not
support including them into the archive.

This patch describes "extended" newc format (newcx) that is based on
newc and has following changes:
- extended attributes support
- increased size of filesize to support files >4GB.
- increased mtime field size to have usec precision and more than
  32-bit of seconds.
- removed unused checksum field.

Signed-off-by: Taras Kondratiuk 
Signed-off-by: Mimi Zohar 
Signed-off-by: Victor Kamensky 
---
 Documentation/early-userspace/buffer-format.txt | 46 ++---
 1 file changed, 41 insertions(+), 5 deletions(-)

diff --git a/Documentation/early-userspace/buffer-format.txt 
b/Documentation/early-userspace/buffer-format.txt
index e1fd7f9dad16..d818df4f72dc 100644
--- a/Documentation/early-userspace/buffer-format.txt
+++ b/Documentation/early-userspace/buffer-format.txt
@@ -24,6 +24,7 @@ grammar, where:
+   indicates concatenation
GZIP()  indicates the gzip(1) of the operand
ALGN(n) means padding with null bytes to an n-byte boundary
+   [n] means size of field is n bytes
 
initramfs  := ("\0" | cpio_archive | cpio_gzip_archive)*
 
@@ -31,20 +32,29 @@ grammar, where:
 
cpio_archive := cpio_file* + ( | cpio_trailer)
 
-   cpio_file := ALGN(4) + cpio_header + filename + "\0" + ALGN(4) + data
+   cpio_file := (cpio_newc_file | cpio_newcx_file)
+
+   cpio_newc_file := ALGN(4) + cpio_newc_header + filename + "\0" + \
+ ALGN(4) + data
+
+   cpio_newcx_file := ALGN(4) + cpio_newcx_header + filename + "\0" + \
+  ALGN(4) + xattrs + ALGN(4) + data
+
+   xattrs := xattr_entry*
+
+   xattr_entry := xattr_size[8] + xattr_name + "\0" + xattr_value
 
cpio_trailer := ALGN(4) + cpio_header + "TRAILER!!!\0" + ALGN(4)
 
 
 In human terms, the initramfs buffer contains a collection of
-compressed and/or uncompressed cpio archives (in the "newc" or "crc"
-formats); arbitrary amounts zero bytes (for padding) can be added
-between members.
+compressed and/or uncompressed cpio archives; arbitrary amounts
+zero bytes (for padding) can be added between members.
 
 The cpio "TRAILER!!!" entry (cpio end-of-archive) is optional, but is
 not ignored; see "handling of hard links" below.
 
-The structure of the cpio_header is as follows (all fields contain
+The structure of the cpio_newc_header is as follows (all fields contain
 hexadecimal ASCII numbers fully padded with '0' on the left to the
 full width of the field, for example, the integer 4780 is represented
 by the ASCII string "12ac"):
@@ -81,6 +91,32 @@ algorithm used.
 If the filename is "TRAILER!!!" this is actually an end-of-archive
 marker; the c_filesize for an end-of-archive marker must be zero.
 
+"Extended" newc format (newcx)
+"newcx" cpio format extends "newc" by increasing size of some fields
+and adding extended attributes support. cpio_newcx_header structure:
+
+Field nameField sizeMeaning
+c_magic   6 bytes   The string "070703"
+c_ino 8 bytes   File inode number
+c_mode8 bytes   File mode and permissions
+c_uid 8 bytes   File uid
+c_gid 8 bytes   File gid
+c_nlink   8 bytes   Number of links
+c_mtime  16 bytes   Modification time (microseconds)
+c_filesize16 bytes  Size of data field
+c_maj 8 bytes   Major part of file device number
+c_min 8 bytes   Minor part of file device number
+c_rmaj8 bytes   Major part of device node reference
+c_rmin8 bytes   Minor part of device node reference
+c_namesize 8 bytes  Length of filename, including final \0
+c_xattrs_size  8 bytes  Size of xattrs field
+
+Most of the fields match cpio_newc_header except c_mtime that contains
+microseconds. c_chksum field is dropped.
+
+xattr_size is a total size of xattr_entry including 8 bytes of
+xattr_size. xattr_size has the same hexadecimal ASCII encoding as other
+fields of cpio header.
 
 *** Handling of hard links
 
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 00/15] extend initramfs archive format to support xattrs

2018-01-24 Thread Taras Kondratiuk
Many of the Linux security/integrity features are dependent on file
metadata, stored as extended attributes (xattrs), for making decisions.
These features need to be initialized during initcall and enabled as
early as possible for complete security coverage. 

Initramfs (tmpfs) supports xattrs, but newc CPIO archive format does not
support including them into the archive.

There are several ways to include xattrs for initramfs:

- Add TAR support. Complicated format and big headers looks like too
  much overhead.

- Include a file manifest containing the xattrs in the CPIO. Should be
  easy for initramfs because we can set xattrs at the end when all files
  are extracted, but extracting such archive in userspace will be more
  complicated. For example it may be necessary to set SELinux labels for
  directories before extracting files into them, so manifest has to be
  extracted first and then searched during each file extraction.

- Extend CPIO header to support xattrs. This seem to be the most
  straight forward way. It also allows to do other useful changes
  to CPIO format at the same time. E.g. increase filesize field to
  support files >4GB.

This patch set extends the existing newc CPIO archive format to include
xattrs in the initramfs.

The series is based on v4.15-rc8. cpio_xattr branch is available here:
https://github.com/kontar/linux/commits/cpio_xattr

=== Patch summary ===

Documentation:
[PATCH 01/15] Documentation: add newcx initramfs format description

Refactoring to simplify adding the new format:
[PATCH 02/15] initramfs: replace states with function pointers
[PATCH 03/15] initramfs: store file name in name_buf
[PATCH 04/15] initramfs: remove unnecessary symlinks processing shortcut
[PATCH 05/15] initramfs: move files creation into separate state
[PATCH 06/15] initramfs: separate reading cpio method from header
[PATCH 07/15] initramfs: split header layout information from parsing
function

Parse newxc format:
[PATCH 08/15] initramfs: add newcx format
[PATCH 09/15] initramfs: set extended attributes

Generate newcx cpio archive:
[PATCH 10/15] gen_init_cpio: move header formatting into function
[PATCH 11/15] gen_init_cpio: add newcx format
[PATCH 12/15] gen_init_cpio: set extended attributes for newcx
[PATCH 13/15] gen_initramfs_list.sh: add -x option to enable newcx

SELinux patches used for testing. They will be sent to SELinux
maintainers separately.
[PATCH 14/15] selinux: allow setxattr on rootfs so initramfs code can
set them
[PATCH 15/15] selinux: delay sid population for rootfs till init is
complete

=== Testing ===

gen_initramfs_list.sh can be used to generate newcx CPIO archive: if
CONFIG_INITRAMFS_NEWCX is enabled CONFIG_INITRAMFS_SOURCE will be packed
into newcx archive. It is enough for basic testing, but it is not
convenient for more complex setup.

Victor have prepared a test setup with SELinux-labeled initramfs based
on Poky(Yocto) with meta-selinux layer.

Repo manifest and build instructions:
https://github.com/victorkamensky/initramfs-xattrs-manifest

Reference cpio utility patch to support newcx format could be
found as part of poky/meta-selinux testing environment at

https://raw.githubusercontent.com/victorkamensky/initramfs-xattrs-poky/rocko/meta/recipes-extended/cpio/cpio-2.12/cpio-xattrs.patch

=== History ===

The patch set is based on Mimi's series from Jan 2015:
https://www.mail-archive.com/initramfs@vger.kernel.org/msg03971.html
Latest discussion I was able to find is from Dec 2015:
https://www.mail-archive.com/initramfs@vger.kernel.org/msg04198.html

Format changes:
- increased size of filesize to 64 bits to support files >4GB.
- increased mtime field size to 64 bits to get usec precision
  and more than 32 bits of seconds. Rob mentioned nsec, but that
  will leave only 34 bits for seconds. If nsec precision is needed
  then we can add a separate 32 bit nsec field (it will match statx).
- Checksum field is replased by xattrs_size field.

Other fields are left unchanged. See patch format description in the
patch #1.

James suggested to add many other changes, but that will bloat header
and make this new format very similar to tar. To keep format simple no
other fields were added.

v2 changes:
- added documentation
- made format more consistent. In previous version a sequence of fields
  in newcx header was different for symlinks and regular files (for
  symlinks data field was before xattrs). It was caused by a flow
  shortcut during symlink entry parsing.
- removed unused checksum field in newcx header
- removed redundant xattrcount at the beginning of xattr section
  (xattrs_size is enough to determine the end of section).
- size of xattr entry in xattr section includes both name and value.
  This makes format more consistent and allows to jump over an entry
  without scanning for the end of name string first.
- streamlined the state machine to address the previous issue and make
  it easier to add the new format
- made header parsing data-driven to remove 

[PATCH v2 12/15] gen_init_cpio: set extended attributes for newcx format

2018-01-24 Thread Taras Kondratiuk
gen_init_cpio creates CPIO archive according to cpio_list manifest file
that contains list of archive entries (one per line). To be able to
store extended attributes in newcx CPIO format we need to pass them via
cpio_list file.

One way of doing it would be to append xattrs to each entry line, but
"file" lines have a variable number of elements because of hardlinks. It
is not obvious how to mark end of hardlinks and start of xattrs in this
case.

This patch introduces a new entry type: "xattr". Each "xattr" line
specify one name=value pair. xattr values are applied to the next
non-xattr line. There can be multiple "xattr" lines before non-xattr
line.

It may be more logical to have xattr lines after corresponding
file entry, but it makes parsing a bit more complex and needs more
intrusive changes.

Xattr value is hex-encoded (see getfattr(1)). Plain string variant would
be easier to read, but special symbols have to be escaped. Hex encoding
is much simpler.

Signed-off-by: Taras Kondratiuk 
---
 usr/gen_init_cpio.c | 142 +++-
 1 file changed, 119 insertions(+), 23 deletions(-)

diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 78a47a5bdcb1..e356f9e532a2 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -50,21 +51,10 @@ static void push_pad (void)
}
 }
 
-static void push_rest(const char *name)
+static void push_string_padded(const char *name)
 {
-   unsigned int name_len = strlen(name) + 1;
-   unsigned int tmp_ofs;
-
-   fputs(name, stdout);
-   putchar(0);
-   offset += name_len;
-
-   tmp_ofs = name_len + cpio_hdr_size;
-   while (tmp_ofs & 3) {
-   putchar(0);
-   offset++;
-   tmp_ofs++;
-   }
+   push_string(name);
+   push_pad();
 }
 
 struct cpio_header {
@@ -137,7 +127,7 @@ static void cpio_trailer(void)
};
 
push_hdr();
-   push_rest(name);
+   push_string_padded(name);
 
while (offset % 512) {
putchar(0);
@@ -145,6 +135,96 @@ static void cpio_trailer(void)
}
 }
 
+struct xattr_hdr {
+   char c_size[8]; /* total size including c_size field */
+   char c_data[];
+};
+static unsigned int xattr_buflen;
+static char xattr_buf[4096];
+
+static void push_xattrs(void)
+{
+   if (!newcx || !xattr_buflen)
+   return;
+
+   if (fwrite(xattr_buf, xattr_buflen, 1, stdout) != 1)
+   fprintf(stderr, "writing xattrs failed\n");
+   offset += xattr_buflen;
+   xattr_buflen = 0;
+
+   push_pad();
+}
+
+static int convert_hex_string(const char *hex_str, char *out, size_t out_size)
+{
+   char buf[3];
+   size_t str_len = strlen(hex_str);
+
+   if (str_len % 2 != 0 || str_len / 2 > out_size)
+   return 0;
+
+   buf[2] = '\0';
+   while (*hex_str != '\0') {
+   buf[0] = *hex_str++;
+   buf[1] = *hex_str++;
+   *out++ = (char)strtol(buf, NULL, 16);
+   }
+
+   return str_len / 2;
+}
+
+static int collect_xattr(const char *line)
+{
+   const char *name, *value;
+   size_t name_len, value_len;
+   char *buf = xattr_buf + xattr_buflen;
+   struct xattr_hdr *hdr = (struct xattr_hdr *)buf;
+   char *bufend = xattr_buf + sizeof(xattr_buf);
+   char *value_buf;
+   size_t xattr_entry_size;
+   char size_str[sizeof(hdr->c_size) + 1];
+
+   if (!newcx)
+   return 0;
+
+   name = line;
+   value = strchr(line, '=');
+   if (!value) {
+   fprintf(stderr, "Unrecognized xattr format '%s'", line);
+   return -1;
+   }
+   name_len = value - name;
+   value++;
+
+   /*
+* For now we support only hex encoded values.
+* String or base64 can be added later.
+*/
+   if (strncmp(value, "0x", 2)) {
+   fprintf(stderr,
+   "Only hex encoded xattr value is supported '%s'",
+   value);
+   return -1;
+   }
+
+   value += 2;
+   value_buf = buf + sizeof(struct xattr_hdr) + name_len + 1;
+   value_len = convert_hex_string(value, value_buf, bufend - value_buf);
+   if (value_len == 0) {
+   fprintf(stderr, "Failed to parse xattr value '%s'", line);
+   return -1;
+   }
+   xattr_entry_size = sizeof(struct xattr_hdr) + name_len + 1 + value_len;
+
+   sprintf(size_str, "%08X", (unsigned int)xattr_entry_size);
+   memcpy(hdr->c_size, size_str, sizeof(hdr->c_size));
+   memcpy(hdr->c_data, name, name_len);
+   hdr->c_data[name_len] = '\0';
+   xattr_buflen += xattr_entry_size;
+
+   return 0;
+}
+
 static int cpio_mkslink(const char *name, const char *target,
 unsigned int mode, uid_t uid, gid_t gid)
 {
@@ -161,12 +241,12 @@ 

[PATCH v2 06/15] initramfs: separate reading cpio method from header

2018-01-24 Thread Taras Kondratiuk
From: Mimi Zohar 

In preparation for adding xattr support, read the CPIO method
separately from the rest of the header.

Signed-off-by: Mimi Zohar 
Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 2d5920c094e0..b3d39c8793be 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -168,7 +168,7 @@ static void __init parse_header(char *s)
int i;
 
buf[8] = '\0';
-   for (i = 0, s += 6; i < 12; i++, s += 8) {
+   for (i = 0; i < 12; i++, s += 8) {
memcpy(buf, s, 8);
parsed[i] = simple_strtoul(buf, NULL, 16);
}
@@ -189,6 +189,7 @@ static void __init parse_header(char *s)
 
 static int __init do_start(void);
 static int __init do_collect(void);
+static int __init do_format(void);
 static int __init do_header(void);
 static int __init do_skip(void);
 static int __init do_name(void);
@@ -233,7 +234,7 @@ static __initdata char *header_buf, *symlink_buf, *name_buf;
 
 static int __init do_start(void)
 {
-   read_into(header_buf, 110, do_header);
+   read_into(header_buf, 6, do_format);
return 0;
 }
 
@@ -251,7 +252,7 @@ static int __init do_collect(void)
return 0;
 }
 
-static int __init do_header(void)
+static int __init do_format(void)
 {
if (memcmp(collected, "070707", 6)==0) {
error("incorrect cpio method used: use -H newc option");
@@ -261,6 +262,12 @@ static int __init do_header(void)
error("no cpio magic");
return 1;
}
+   read_into(header_buf, 104, do_header);
+   return 0;
+}
+
+static int __init do_header(void)
+{
parse_header(collected);
next_header = this_header + N_ALIGN(name_len) + body_len;
next_header = (next_header + 3) & ~3;
@@ -457,7 +464,7 @@ static char * __init unpack_to_rootfs(char *buf, unsigned 
long len)
const char *compress_name;
static __initdata char msg_buf[64];
 
-   header_buf = kmalloc(110, GFP_KERNEL);
+   header_buf = kmalloc(104, GFP_KERNEL);
symlink_buf = kmalloc(PATH_MAX + 1, GFP_KERNEL);
name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
 
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 03/15] initramfs: store file name in name_buf

2018-01-24 Thread Taras Kondratiuk
There is already name_buf buffer pre-allocated for a file name. No need
to allocate vcollected for every file. More over a name can be already
stored in name_buf by read_info() function.

Add memcpy_optional() function to handle such case.

Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 49cd2681a26f..b6ee675e5cdb 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -210,7 +210,6 @@ static inline void __init eat(unsigned n)
byte_count -= n;
 }
 
-static __initdata char *vcollected;
 static __initdata char *collected;
 static long remains __initdata;
 static __initdata char *collect;
@@ -324,6 +323,13 @@ static void __init clean_path(char *path, umode_t fmode)
}
 }
 
+static void *memcpy_optional(void *dest, const void *src, size_t n)
+{
+   if (dest != src)
+   return memcpy(dest, src, n);
+   return dest;
+}
+
 static __initdata int wfd;
 
 static int __init do_name(void)
@@ -348,7 +354,8 @@ static int __init do_name(void)
sys_fchmod(wfd, mode);
if (body_len)
sys_ftruncate(wfd, body_len);
-   vcollected = kstrdup(collected, GFP_KERNEL);
+   memcpy_optional(name_buf, collected,
+   N_ALIGN(name_len));
state = do_copy;
}
}
@@ -375,8 +382,7 @@ static int __init do_copy(void)
if (xwrite(wfd, victim, body_len) != body_len)
error("write error");
sys_close(wfd);
-   do_utime(vcollected, mtime);
-   kfree(vcollected);
+   do_utime(name_buf, mtime);
eat(body_len);
state = do_skip;
return 0;
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 13/15] gen_initramfs_list.sh: add -x option to enable newcx format

2018-01-24 Thread Taras Kondratiuk
From: Mimi Zohar 

-x option populates extended attributes in cpio_list file passed to
get_init_cpio and selects newcx CPIO format.

Signed-off-by: Mimi Zohar 
Signed-off-by: Taras Kondratiuk 
---
 scripts/gen_initramfs_list.sh | 13 -
 usr/Kconfig   | 11 +++
 usr/Makefile  |  3 ++-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index 86a3c0e5cfbc..cddb82f093d9 100755
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -24,6 +24,7 @@ $0 [-o ] [-u ] [-g ] {-d | } ...
-gGroup ID to map to group ID 0 (root).
is only meaningful if  is a
   directory.  "squash" forces all files to gid 0.
+   -x include file extended attributes in cpio archive.
  File list or directory for cpio archive.
   If  is a .cpio file it will be used
   as direct input to initramfs.
@@ -146,6 +147,9 @@ parse() {
;;
esac
 
+   $include_xattrs && \
+   getfattr -h -d -m - -e hex --absolute-names ${location} | \
+   sed -e '/^#/d' -e '/^$/d' -e 's/^/xattr /' >> ${output}
echo "${str}" >> ${output}
 
return 0
@@ -226,6 +230,8 @@ root_gid=0
 dep_list=
 cpio_file=
 cpio_list=
+cpio_opts=
+include_xattrs=false
 output="/dev/stdout"
 output_file=""
 is_cpio_compressed=
@@ -283,6 +289,10 @@ while [ $# -gt 0 ]; do
default_list="$arg"
${dep_list}default_initramfs
;;
+   "-x")   # include extended attributers
+   cpio_opts="-x"
+   include_xattrs=true
+   ;;
"-h")
usage
exit 0
@@ -312,7 +322,8 @@ if [ ! -z ${output_file} ]; then
fi
fi
cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XX)"
-   usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile}
+   usr/gen_init_cpio $timestamp ${cpio_opts} ${cpio_list} \
+   > ${cpio_tfile}
else
cpio_tfile=${cpio_file}
fi
diff --git a/usr/Kconfig b/usr/Kconfig
index 43658b8a975e..0cc03bc4614c 100644
--- a/usr/Kconfig
+++ b/usr/Kconfig
@@ -52,6 +52,17 @@ config INITRAMFS_ROOT_GID
 
  If you are not sure, leave it set to "0".
 
+config INITRAMFS_NEWCX
+   bool "Use newcx CPIO format for initramfs"
+   depends on INITRAMFS_SOURCE!=""
+   default n
+   help
+ If selected "usr/gen_init_cpio" will generate newcx CPIO archive
+ format that supports extended attributes.
+
+ See  for
+ more details.
+
 config RD_GZIP
bool "Support initial ramdisk/ramfs compressed using gzip"
depends on BLK_DEV_INITRD
diff --git a/usr/Makefile b/usr/Makefile
index 237a028693ce..1106bfd61475 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -29,7 +29,8 @@ ramfs-input := $(if $(filter-out 
"",$(CONFIG_INITRAMFS_SOURCE)), \
$(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d)
 ramfs-args  := \
 $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
-$(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
+$(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
+$(if $(CONFIG_INITRAMFS_NEWCX), -x)
 
 # $(datafile_d_y) is used to identify all files included
 # in initramfs and to detect if any files are added/removed.
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 09/15] initramfs: set extended attributes

2018-01-24 Thread Taras Kondratiuk
From: Mimi Zohar 

This patch writes out the extended attributes included in the cpio file.
As the "security.ima" xattr needs to be written after the file data.
this patch separates extracting and setting the xattrs by defining new
do_setxattrs state.

[kamensky: fixed restoring of xattrs for symbolic links by using
   sys_lsetxattr() instead of sys_setxattr()]

Signed-off-by: Mimi Zohar 
Signed-off-by: Victor Kamensky 
Signed-off-by: Taras Kondratiuk 
---
 init/initramfs.c | 57 +++-
 1 file changed, 52 insertions(+), 5 deletions(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index 3d0f46c28459..040e26cf451a 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -310,6 +310,7 @@ static int __init do_xattrs(void);
 static int __init do_create(void);
 static int __init do_copy(void);
 static int __init do_symlink(void);
+static int __init do_setxattrs(void);
 static int __init do_reset(void);
 
 typedef int (*fsm_state_t)(void);
@@ -472,7 +473,7 @@ static int __init do_name(void)
 
 static int __init do_xattrs(void)
 {
-   /* Do nothing for now */
+   memcpy_optional(xattr_buf, collected, xattr_len);
state = do_create;
return 0;
 }
@@ -481,8 +482,7 @@ static __initdata int wfd;
 
 static int __init do_create(void)
 {
-   state = do_skip;
-   next_state = do_reset;
+   state = do_setxattrs;
clean_path(name_buf, mode);
if (S_ISREG(mode)) {
int ml = maybe_link(name_buf);
@@ -515,8 +515,11 @@ static int __init do_create(void)
do_utime(name_buf, mtime);
}
} else if (S_ISLNK(mode)) {
-   if (body_len > PATH_MAX)
+   if (body_len > PATH_MAX) {
+   state = do_skip;
+   next_state = do_reset;
return 0;
+   }
read_into(symlink_buf, body_len, do_symlink);
}
return 0;
@@ -530,7 +533,7 @@ static int __init do_copy(void)
sys_close(wfd);
do_utime(name_buf, mtime);
eat(body_len);
-   state = do_skip;
+   state = do_setxattrs;
return 0;
} else {
if (xwrite(wfd, victim, byte_count) != byte_count)
@@ -549,8 +552,52 @@ static int __init do_symlink(void)
sys_symlink(symlink_buf, name_buf);
sys_lchown(name_buf, uid, gid);
do_utime(name_buf, mtime);
+   state = do_setxattrs;
+   return 0;
+}
+
+struct xattr_hdr {
+   char c_size[8]; /* total size including c_size field */
+   char c_data[];  /* \0 */
+};
+
+static int __init do_setxattrs(void)
+{
+   char *buf = xattr_buf;
+   char *bufend = buf + xattr_len;
+   struct xattr_hdr *hdr;
+   char str[sizeof(hdr->c_size) + 1];
+
state = do_skip;
next_state = do_reset;
+   if (!xattr_len)
+   return 0;
+
+   str[sizeof(hdr->c_size)] = 0;
+
+   while (buf < bufend) {
+   char *xattr_name, *xattr_value;
+   unsigned long xattr_entry_size, xattr_value_size;
+   int ret;
+
+   hdr = (struct xattr_hdr *)buf;
+   memcpy(str, hdr->c_size, sizeof(hdr->c_size));
+   ret = kstrtoul(str, 16, _entry_size);
+   buf += xattr_entry_size;
+   if (ret || buf > bufend) {
+   error("malformed xattrs");
+   break;
+   }
+
+   xattr_name = hdr->c_data;
+   xattr_value = xattr_name + strlen(xattr_name) + 1;
+   xattr_value_size = buf - xattr_value;
+
+   ret = sys_lsetxattr(name_buf, xattr_name, xattr_value,
+   xattr_value_size, 0);
+   pr_debug("%s: %s size: %lu val: %s (ret: %d)\n", name_buf,
+   xattr_name, xattr_value_size, xattr_value, ret);
+   }
return 0;
 }
 
-- 
2.10.3.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 10/15] gen_init_cpio: move header formatting into function

2018-01-24 Thread Taras Kondratiuk
CPIO header is generated in multiple places with the same sprintf()
format string. Move formatting into a single function in preparation
to adding a new cpio format.

Signed-off-by: Taras Kondratiuk 
---
 usr/gen_init_cpio.c | 186 ++--
 1 file changed, 92 insertions(+), 94 deletions(-)

diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 03b21189d58b..7a2a6d85345d 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -64,34 +64,55 @@ static void push_rest(const char *name)
}
 }
 
-static void push_hdr(const char *s)
+struct cpio_header {
+   unsigned int ino;
+   unsigned int mode;
+   uid_t uid;
+   gid_t gid;
+   unsigned int nlink;
+   time_t mtime;
+   size_t filesize;
+   int devmajor;
+   int devminor;
+   int rdevmajor;
+   int rdevminor;
+   size_t namesize;
+   unsigned int check;
+};
+
+static void push_hdr(const struct cpio_header *hdr)
 {
+   char s[256];
+
+   sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
+  "%08X%08X%08X%08X%08X%08X%08X",
+   "070701",
+   hdr->ino,
+   hdr->mode,
+   (long)hdr->uid,
+   (long)hdr->gid,
+   hdr->nlink,
+   (long)hdr->mtime,
+   (unsigned int)hdr->filesize,
+   hdr->devmajor,
+   hdr->devminor,
+   hdr->rdevmajor,
+   hdr->rdevminor,
+   (unsigned int)hdr->namesize,
+   hdr->check);
fputs(s, stdout);
offset += 110;
 }
 
 static void cpio_trailer(void)
 {
-   char s[256];
const char name[] = "TRAILER!!!";
+   struct cpio_header hdr = {
+   .nlink = 1,
+   .namesize = strlen(name)+1,
+   };
 
-   sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
-  "%08X%08X%08X%08X%08X%08X%08X",
-   "070701",   /* magic */
-   0,  /* ino */
-   0,  /* mode */
-   (long) 0,   /* uid */
-   (long) 0,   /* gid */
-   1,  /* nlink */
-   (long) 0,   /* mtime */
-   0,  /* filesize */
-   0,  /* major */
-   0,  /* minor */
-   0,  /* rmajor */
-   0,  /* rminor */
-   (unsigned)strlen(name)+1, /* namesize */
-   0); /* chksum */
-   push_hdr(s);
+   push_hdr();
push_rest(name);
 
while (offset % 512) {
@@ -103,27 +124,21 @@ static void cpio_trailer(void)
 static int cpio_mkslink(const char *name, const char *target,
 unsigned int mode, uid_t uid, gid_t gid)
 {
-   char s[256];
-
if (name[0] == '/')
name++;
-   sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
-  "%08X%08X%08X%08X%08X%08X%08X",
-   "070701",   /* magic */
-   ino++,  /* ino */
-   S_IFLNK | mode, /* mode */
-   (long) uid, /* uid */
-   (long) gid, /* gid */
-   1,  /* nlink */
-   (long) default_mtime,   /* mtime */
-   (unsigned)strlen(target)+1, /* filesize */
-   3,  /* major */
-   1,  /* minor */
-   0,  /* rmajor */
-   0,  /* rminor */
-   (unsigned)strlen(name) + 1,/* namesize */
-   0); /* chksum */
-   push_hdr(s);
+   struct cpio_header hdr = {
+   .ino = ino++,
+   .mode = S_IFLNK | mode,
+   .uid = uid,
+   .gid = gid,
+   .nlink = 1,
+   .mtime = default_mtime,
+   .filesize = strlen(target)+1,
+   .devmajor = 3,
+   .devminor = 1,
+   .namesize = strlen(name)+1,
+   };
+   push_hdr();
push_string(name);
push_pad();
push_string(target);
@@ -152,27 +167,20 @@ static int cpio_mkslink_line(const char *line)
 static int cpio_mkgeneric(const char *name, unsigned int mode,
   uid_t uid, gid_t gid)
 {
-   char s[256];
-
if (name[0] == '/')
name++;
-   sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
-  "%08X%08X%08X%08X%08X%08X%08X",
-   "070701",   /* magic */
-   ino++,  /* ino */
-   mode,   /* mode */
-   (long) uid, /* uid */
-   (long) gid, /* gid */
- 

[PATCH v2 11/15] gen_init_cpio: add newcx format

2018-01-24 Thread Taras Kondratiuk
Add "newcx" format that supports extended attributes and has increased
size of c_mtime and c_filesize fields.

Added -x option to select "newcx" format. Default is "newc".

Refer to Documentation/early-userspace/buffer-format.txt for detailed
format description.

Signed-off-by: Taras Kondratiuk 
---
 usr/gen_init_cpio.c | 70 +
 1 file changed, 49 insertions(+), 21 deletions(-)

diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 7a2a6d85345d..78a47a5bdcb1 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * Original work by Jeff Garzik
@@ -21,6 +22,8 @@
 #define xstr(s) #s
 #define str(s) xstr(s)
 
+static int newcx;
+static unsigned int cpio_hdr_size;
 static unsigned int offset;
 static unsigned int ino = 721;
 static time_t default_mtime;
@@ -56,7 +59,7 @@ static void push_rest(const char *name)
putchar(0);
offset += name_len;
 
-   tmp_ofs = name_len + 110;
+   tmp_ofs = name_len + cpio_hdr_size;
while (tmp_ofs & 3) {
putchar(0);
offset++;
@@ -77,6 +80,7 @@ struct cpio_header {
int rdevmajor;
int rdevminor;
size_t namesize;
+   size_t xattrsize;
unsigned int check;
 };
 
@@ -84,24 +88,44 @@ static void push_hdr(const struct cpio_header *hdr)
 {
char s[256];
 
-   sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
-  "%08X%08X%08X%08X%08X%08X%08X",
-   "070701",
-   hdr->ino,
-   hdr->mode,
-   (long)hdr->uid,
-   (long)hdr->gid,
-   hdr->nlink,
-   (long)hdr->mtime,
-   (unsigned int)hdr->filesize,
-   hdr->devmajor,
-   hdr->devminor,
-   hdr->rdevmajor,
-   hdr->rdevminor,
-   (unsigned int)hdr->namesize,
-   hdr->check);
+   if (newcx) {
+   sprintf(s, "%s%08X%08X%08lX%08lX%08X%016llX"
+  "%016llX%08X%08X%08X%08X%08X%08X",
+   "070703",
+   hdr->ino,
+   hdr->mode,
+   (long)hdr->uid,
+   (long)hdr->gid,
+   hdr->nlink,
+   hdr->mtime * 100ULL,
+   (long long)hdr->filesize,
+   hdr->devmajor,
+   hdr->devminor,
+   hdr->rdevmajor,
+   hdr->rdevminor,
+   (unsigned int)hdr->namesize,
+   (unsigned int)hdr->xattrsize);
+   } else {
+   sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
+  "%08X%08X%08X%08X%08X%08X%08X",
+   "070701",
+   hdr->ino,
+   hdr->mode,
+   (long)hdr->uid,
+   (long)hdr->gid,
+   hdr->nlink,
+   (long)hdr->mtime,
+   (unsigned int)hdr->filesize,
+   hdr->devmajor,
+   hdr->devminor,
+   hdr->rdevmajor,
+   hdr->rdevminor,
+   (unsigned int)hdr->namesize,
+   hdr->check);
+   }
fputs(s, stdout);
-   offset += 110;
+   assert((offset & 3) == 0);
+   offset += cpio_hdr_size;
 }
 
 static void cpio_trailer(void)
@@ -301,7 +325,7 @@ static int cpio_mkfile(const char *name, const char 
*location,
 {
char *filebuf = NULL;
struct stat buf;
-   long size;
+   size_t size;
int file = -1;
int retval;
int rc = -1;
@@ -450,7 +474,7 @@ static int cpio_mkfile_line(const char *line)
 static void usage(const char *prog)
 {
fprintf(stderr, "Usage:\n"
-   "\t%s [-t ] \n"
+   "\t%s [-t ] [-x] \n"
"\n"
" is a file containing newline separated entries 
that\n"
"describe the files to be included in the initramfs archive:\n"
@@ -527,7 +551,7 @@ int main (int argc, char *argv[])
 
default_mtime = time(NULL);
while (1) {
-   int opt = getopt(argc, argv, "t:h");
+   int opt = getopt(argc, argv, "t:h:x");
char *invalid;
 
if (opt == -1)
@@ -542,12 +566,16 @@ int main (int argc, char *argv[])
exit(1);
}
break;
+   case 'x':
+   newcx = 1;
+   break;
case 'h':
case '?':
usage(argv[0]);
exit(opt == 'h' ? 0 : 1);
}
}
+   cpio_hdr_size = newcx ? 134 : 110;
 
if (argc - optind != 1) 

Re: [RFC tip/locking/lockdep v4 16/17] lockdep: Documention for recursive read lock detection reasoning

2018-01-24 Thread Boqun Feng
On Wed, Jan 24, 2018 at 05:05:49PM -0800, Randy Dunlap wrote:
> On 01/09/2018 06:38 AM, Boqun Feng wrote:
> > As now we support recursive read lock deadlock detection, add related
> > explanation in the Documentation/lockdep/lockdep-desgin.txt:
> > 
> > *   Definition of recursive read locks, non-recursive locks, strong
> > dependency path and notions of -(**)->.
> > 
> > *   Lockdep's assumption.
> > 
> > *   Informal proof of recursive read lock deadlock detection.
> > 
> > Signed-off-by: Boqun Feng 
> > ---
> >  Documentation/locking/lockdep-design.txt | 170 
> > +++
> >  1 file changed, 170 insertions(+)
> > 
> > diff --git a/Documentation/locking/lockdep-design.txt 
> > b/Documentation/locking/lockdep-design.txt
> > index 382bc25589c2..0e674305f96a 100644
> > --- a/Documentation/locking/lockdep-design.txt
> > +++ b/Documentation/locking/lockdep-design.txt
> > @@ -284,3 +284,173 @@ Run the command and save the output, then compare 
> > against the output from
> >  a later run of this command to identify the leakers.  This same output
> >  can also help you find situations where runtime lock initialization has
> >  been omitted.
> > +
> > +Recursive Read Deadlock Detection:
> > +--
> > +Lockdep now is equipped with deadlock detection for recursive read locks.
> > +
> > +Recursive read locks, as their name indicates, are the locks able to be
> > +acquired recursively, unlike non-recursive read locks, recursive read locks
> 
> recursively. Unlike
> 
> > +only get blocked by current write lock *holders* other than write lock
> > +*waiters*, for example:
> > +
> > +   TASK A: TASK B:
> > +
> > +   read_lock(X);
> > +
> > +   write_lock(X);
> > +
> > +   read_lock(X);
> > +
> > +is not a deadlock for recursive read locks, as while the task B is waiting 
> > for
> > +the lock X, the second read_lock() doesn't need to wait because it's a 
> > recursive
> > +read lock.
> > +
> > +Note that a lock can be a write lock(exclusive lock), a non-recursive read 
> > lock
> > +(non-recursive shared lock) or a recursive read lock(recursive shared 
> > lock),
> > +depending on the API used to acquire it(more detailedly, the value of the
> 
>more specifically,
> 
> > +'read' parameter for lock_acquire(...)). In other words, a single lock 
> > instance
> > +have three types of acquisition depending on the acquisition functions:
> 
>has three types
> 
> > +exclusive, non-recursive read, and recursive read.
> > +
> > +That said, recursive read locks could introduce deadlocks too, considering 
> > the
> > +following:
> > +
> > +   TASK A: TASK B:
> > +
> > +   read_lock(X);
> > +   read_lock(Y);
> > +   write_lock(Y);
> > +   write_lock(X);
> > +
> > +, neither task could get the write locks because the corresponding read 
> > locks
> > +are held by each other.
> > +
> > +Lockdep could detect recursive read lock related deadlocks. The 
> > dependencies(edges)
> > +in the lockdep graph are classified into four categories:
> > +
> > +1) -(NN)->: non-recursive to non-recursive dependency, non-recursive locks 
> > include
> > +non-recursive read locks, write locks and exclusive locks(e.g. 
> > spinlock_t),
> 
>   
> spinlock_t).
> 
> > +   they are treated equally in deadlock detection. "X -(NN)-> Y" means
> 
> They
> 
> > +X -> Y and both X and Y are non-recursive locks.
> > +
> > +2) -(RN)->: recursive to non-recursive dependency, recursive locks means 
> > recursive read
> > +   locks. "X -(RN)-> Y" means X -> Y and X is recursive read lock and
> > +Y is non-recursive lock.
> > +
> > +3) -(NR)->: non-recursive to recursive dependency, "X -(NR)-> Y" means X 
> > -> Y and X is
> > +non-recursive lock and Y is recursive lock.
> > +
> > +4) -(RR)->: recursive to recursive dependency, "X -(RR)-> Y" means X -> Y 
> > and both X
> > +and Y are recursive locks.
> > +
> > +Note that given two locks, they may have multiple dependencies between 
> > them, for example:
> > +
> > +   TASK A:
> > +
> > +   read_lock(X);
> > +   write_lock(Y);
> > +   ...
> > +
> > +   TASK B:
> > +
> > +   write_lock(X);
> > +   write_lock(Y);
> > +
> > +, we have both X -(RN)-> Y and X -(NN)-> Y in the dependency graph.
> > +
> > +And obviously a non-recursive lock can block the corresponding recursive 
> > lock,
> > +and vice versa. Besides a non-recursive lock may block the other 
> > non-recursive
> > +lock of the same instance(e.g. a write lock may block a corresponding
> > +non-recursive read lock and vice versa).
> > +
> > +We use -(*N)-> for edges that is either -(RN)-> or -(NN)->, the similar 
> > for -(N*)->,
> > +-(*R)-> and -(R*)->
> > +
> > +A 

Re: [RFC tip/locking/lockdep v4 16/17] lockdep: Documention for recursive read lock detection reasoning

2018-01-24 Thread Randy Dunlap
On 01/09/2018 06:38 AM, Boqun Feng wrote:
> As now we support recursive read lock deadlock detection, add related
> explanation in the Documentation/lockdep/lockdep-desgin.txt:
> 
> * Definition of recursive read locks, non-recursive locks, strong
>   dependency path and notions of -(**)->.
> 
> * Lockdep's assumption.
> 
> * Informal proof of recursive read lock deadlock detection.
> 
> Signed-off-by: Boqun Feng 
> ---
>  Documentation/locking/lockdep-design.txt | 170 
> +++
>  1 file changed, 170 insertions(+)
> 
> diff --git a/Documentation/locking/lockdep-design.txt 
> b/Documentation/locking/lockdep-design.txt
> index 382bc25589c2..0e674305f96a 100644
> --- a/Documentation/locking/lockdep-design.txt
> +++ b/Documentation/locking/lockdep-design.txt
> @@ -284,3 +284,173 @@ Run the command and save the output, then compare 
> against the output from
>  a later run of this command to identify the leakers.  This same output
>  can also help you find situations where runtime lock initialization has
>  been omitted.
> +
> +Recursive Read Deadlock Detection:
> +--
> +Lockdep now is equipped with deadlock detection for recursive read locks.
> +
> +Recursive read locks, as their name indicates, are the locks able to be
> +acquired recursively, unlike non-recursive read locks, recursive read locks

recursively. Unlike

> +only get blocked by current write lock *holders* other than write lock
> +*waiters*, for example:
> +
> + TASK A: TASK B:
> +
> + read_lock(X);
> +
> + write_lock(X);
> +
> + read_lock(X);
> +
> +is not a deadlock for recursive read locks, as while the task B is waiting 
> for
> +the lock X, the second read_lock() doesn't need to wait because it's a 
> recursive
> +read lock.
> +
> +Note that a lock can be a write lock(exclusive lock), a non-recursive read 
> lock
> +(non-recursive shared lock) or a recursive read lock(recursive shared lock),
> +depending on the API used to acquire it(more detailedly, the value of the

   more specifically,

> +'read' parameter for lock_acquire(...)). In other words, a single lock 
> instance
> +have three types of acquisition depending on the acquisition functions:

   has three types

> +exclusive, non-recursive read, and recursive read.
> +
> +That said, recursive read locks could introduce deadlocks too, considering 
> the
> +following:
> +
> + TASK A: TASK B:
> +
> + read_lock(X);
> + read_lock(Y);
> + write_lock(Y);
> + write_lock(X);
> +
> +, neither task could get the write locks because the corresponding read locks
> +are held by each other.
> +
> +Lockdep could detect recursive read lock related deadlocks. The 
> dependencies(edges)
> +in the lockdep graph are classified into four categories:
> +
> +1) -(NN)->: non-recursive to non-recursive dependency, non-recursive locks 
> include
> +non-recursive read locks, write locks and exclusive locks(e.g. 
> spinlock_t),

  
spinlock_t).

> + they are treated equally in deadlock detection. "X -(NN)-> Y" means

They

> +X -> Y and both X and Y are non-recursive locks.
> +
> +2) -(RN)->: recursive to non-recursive dependency, recursive locks means 
> recursive read
> + locks. "X -(RN)-> Y" means X -> Y and X is recursive read lock and
> +Y is non-recursive lock.
> +
> +3) -(NR)->: non-recursive to recursive dependency, "X -(NR)-> Y" means X -> 
> Y and X is
> +non-recursive lock and Y is recursive lock.
> +
> +4) -(RR)->: recursive to recursive dependency, "X -(RR)-> Y" means X -> Y 
> and both X
> +and Y are recursive locks.
> +
> +Note that given two locks, they may have multiple dependencies between them, 
> for example:
> +
> + TASK A:
> +
> + read_lock(X);
> + write_lock(Y);
> + ...
> +
> + TASK B:
> +
> + write_lock(X);
> + write_lock(Y);
> +
> +, we have both X -(RN)-> Y and X -(NN)-> Y in the dependency graph.
> +
> +And obviously a non-recursive lock can block the corresponding recursive 
> lock,
> +and vice versa. Besides a non-recursive lock may block the other 
> non-recursive
> +lock of the same instance(e.g. a write lock may block a corresponding
> +non-recursive read lock and vice versa).
> +
> +We use -(*N)-> for edges that is either -(RN)-> or -(NN)->, the similar for 
> -(N*)->,
> +-(*R)-> and -(R*)->
> +
> +A "path" is a series of conjunct dependency edges in the graph. And we 
> define a
> +"strong" path, which indicates the strong dependency throughout each 
> dependency
> +in the path, as the path that doesn't have two conjunct edges(dependencies) 
> as
> +-(*R)-> and -(R*)->. IOW, a "strong" path is a path from a 

Re: [v2,3/7] soc: qcom: Add GENI based QUP Wrapper driver

2018-01-24 Thread Evan Green
On Fri, Jan 12, 2018 at 5:05 PM, Karthikeyan Ramasubramanian
 wrote:
> This driver manages the Generic Interface (GENI) firmware based Qualcomm
> Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation
> programmable module composed of multiple Serial Engines (SE) and supports
> a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This
> driver also enables managing the serial interface independent aspects of
> Serial Engines.
>
> Signed-off-by: Karthikeyan Ramasubramanian 
> Signed-off-by: Sagar Dharia 
> Signed-off-by: Girish Mahadevan 
> ---
>  drivers/soc/qcom/Kconfig|8 +
>  drivers/soc/qcom/Makefile   |1 +
>  drivers/soc/qcom/qcom-geni-se.c | 1016 
> +++
>  include/linux/qcom-geni-se.h|  807 +++
>  4 files changed, 1832 insertions(+)
>  create mode 100644 drivers/soc/qcom/qcom-geni-se.c
>  create mode 100644 include/linux/qcom-geni-se.h

I'm a newbie here, just starting to get up to speed. Please forgive
any indiscretions. But I am interested in this driver, so I'm throwing
in my minor comments.


> +/**
> + * geni_se_setup_m_cmd() - Setup the primary sequencer
> + * @base:  Base address of the serial engine's register block.
> + * @cmd:   Command/Operation to setup in the primary sequencer.
> + * @params:Parameter for the sequencer command.
> + *
> + * This function is used to configure the primary sequencer with the
> + * command and its assoicated parameters.
> + */
> +void geni_se_setup_m_cmd(void __iomem *base, u32 cmd, u32 params);
> +
> +/**
> + * geni_se_setup_s_cmd() - Setup the secondary sequencer
> + * @base:  Base address of the serial engine's register block.
> + * @cmd:   Command/Operation to setup in the secondary sequencer.
> + * @params:Parameter for the sequencer command.
> + *
> + * This function is used to configure the secondary sequencer with the
> + * command and its assoicated parameters.
> + */
> +void geni_se_setup_s_cmd(void __iomem *base, u32 cmd, u32 params);
> +

s/assoicated/associated/ (twice)


> +/**
> + * geni_se_tx_dma_prep() - Prepare the Serial Engine for TX DMA transfer
> + * @wrapper_dev:   QUP Wrapper Device to which the TX buffer is mapped.
> + * @base:  Base address of the SE register block.
> + * @tx_buf:Pointer to the TX buffer.
> + * @tx_len:Length of the TX buffer.
> + * @tx_dma:Pointer to store the mapped DMA address.
> + *
> + * This function is used to prepare the buffers for DMA TX.
> + *
> + * Return: 0 on success, standard Linux error codes on error/failure.
> + */
> +int geni_se_tx_dma_prep(struct device *wrapper_dev, void __iomem *base,
> +   void *tx_buf, int tx_len, dma_addr_t *tx_dma)
> +{
> +   int ret;
> +
> +   if (unlikely(!wrapper_dev || !base || !tx_buf || !tx_len || !tx_dma))
> +   return -EINVAL;
> +
> +   ret = geni_se_map_buf(wrapper_dev, tx_dma, tx_buf, tx_len,
> +   DMA_TO_DEVICE);
> +   if (ret)
> +   return ret;
> +
> +   geni_write_reg(7, base, SE_DMA_TX_IRQ_EN_SET);
> +   geni_write_reg((u32)(*tx_dma), base, SE_DMA_TX_PTR_L);
> +   geni_write_reg((u32)((*tx_dma) >> 32), base, SE_DMA_TX_PTR_H);
> +   geni_write_reg(1, base, SE_DMA_TX_ATTR);

Bjorn touched on this, but as someone trying to understand what's
going on it would be great to see #defines for the magic values in
here (7 and 1)

> +void geni_se_get_packing_config(int bpw, int pack_words, bool msb_to_lsb,
> +   unsigned long *cfg0, unsigned long *cfg1)
> +{
> +   u32 cfg[4] = {0};
> +   int len;
> +   int temp_bpw = bpw;
> +   int idx_start = (msb_to_lsb ? (bpw - 1) : 0);
> +   int idx = idx_start;
> +   int idx_delta = (msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE);
> +   int ceil_bpw = ((bpw & (BITS_PER_BYTE - 1)) ?
> +   ((bpw & ~(BITS_PER_BYTE - 1)) + BITS_PER_BYTE) : bpw);
> +   int iter = (ceil_bpw * pack_words) >> 3;

Is the shift by 3 here really meant to divide by BITS_PER_BYTE? It
might be clearer to divide by BITS_PER_BYTE and let the compiler
convert that into a shift.

> +   int i;
> +
> +   if (unlikely(iter <= 0 || iter > 4)) {
> +   *cfg0 = 0;
> +   *cfg1 = 0;
> +   return;
> +   }
> +
> +   for (i = 0; i < iter; i++) {
> +   len = (temp_bpw < BITS_PER_BYTE) ?
> +   (temp_bpw - 1) : BITS_PER_BYTE - 1;
> +   cfg[i] = ((idx << 5) | (msb_to_lsb << 4) | (len << 1));

...more magic numbers here. These are register bitfields? It would be
great to get the field shifts defined.

> +   idx = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
> +   ((i + 1) * 

Re: [v2, 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

2018-01-24 Thread Evan Green
On Fri, Jan 12, 2018 at 5:05 PM, Karthikeyan Ramasubramanian
 wrote:
> +static int get_clk_cfg(unsigned long clk_freq, unsigned long *ser_clk)
> +{
> +   unsigned long root_freq[] = {7372800, 14745600, 1920, 29491200,
> +   3200, 4800, 6400, 8000, 9600, 1};

This table should be static const, right?
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [v2, 5/7] i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller

2018-01-24 Thread Evan Green
On Fri, Jan 12, 2018 at 5:05 PM, Karthikeyan Ramasubramanian
 wrote:
> This bus driver supports the GENI based i2c hardware controller in the
> Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable
> module supporting a wide range of serial interfaces including I2C. The
> driver supports FIFO mode and DMA mode of transfer and switches modes
> dynamically depending on the size of the transfer.
>
> Signed-off-by: Karthikeyan Ramasubramanian 
> Signed-off-by: Sagar Dharia 
> Signed-off-by: Girish Mahadevan 
> ---
>  drivers/i2c/busses/Kconfig |  10 +
>  drivers/i2c/busses/Makefile|   1 +
>  drivers/i2c/busses/i2c-qcom-geni.c | 656 
> +
>  3 files changed, 667 insertions(+)
>  create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c

Newbie again, throwing in my two cents.

> +static inline void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c, int dfs)
> +{
> +   struct geni_i2c_clk_fld *itr = geni_i2c_clk_map + gi2c->clk_fld_idx;
> +
> +   geni_write_reg(dfs, gi2c->base, SE_GENI_CLK_SEL);
> +
> +   geni_write_reg((itr->clk_div << 4) | 1, gi2c->base, 
> GENI_SER_M_CLK_CFG);
> +   geni_write_reg(((itr->t_high << 20) | (itr->t_low << 10) |
> +   itr->t_cycle), gi2c->base, SE_I2C_SCL_COUNTERS);

It would be great to get these register field shifts defined, as
they're otherwise fairly opaque.

> +static irqreturn_t geni_i2c_irq(int irq, void *dev)
> +{
> +   struct geni_i2c_dev *gi2c = dev;
> +   int i, j;
> +   u32 m_stat = readl_relaxed(gi2c->base + SE_GENI_M_IRQ_STATUS);
> +   u32 rx_st = readl_relaxed(gi2c->base + SE_GENI_RX_FIFO_STATUS);
> +   u32 dm_tx_st = readl_relaxed(gi2c->base + SE_DMA_TX_IRQ_STAT);
> +   u32 dm_rx_st = readl_relaxed(gi2c->base + SE_DMA_RX_IRQ_STAT);
> +   u32 dma = readl_relaxed(gi2c->base + SE_GENI_DMA_MODE_EN);
> +   struct i2c_msg *cur = gi2c->cur;
> +
> +   if (!cur || (m_stat & M_CMD_FAILURE_EN) ||
> +   (dm_rx_st & (DM_I2C_CB_ERR)) ||
> +   (m_stat & M_CMD_ABORT_EN)) {
> +
> +   if (m_stat & M_GP_IRQ_1_EN)
> +   geni_i2c_err(gi2c, I2C_NACK);
> +   if (m_stat & M_GP_IRQ_3_EN)
> +   geni_i2c_err(gi2c, I2C_BUS_PROTO);
> +   if (m_stat & M_GP_IRQ_4_EN)
> +   geni_i2c_err(gi2c, I2C_ARB_LOST);
> +   if (m_stat & M_CMD_OVERRUN_EN)
> +   geni_i2c_err(gi2c, GENI_OVERRUN);
> +   if (m_stat & M_ILLEGAL_CMD_EN)
> +   geni_i2c_err(gi2c, GENI_ILLEGAL_CMD);
> +   if (m_stat & M_CMD_ABORT_EN)
> +   geni_i2c_err(gi2c, GENI_ABORT_DONE);
> +   if (m_stat & M_GP_IRQ_0_EN)
> +   geni_i2c_err(gi2c, GP_IRQ0);
> +
> +   if (!dma)
> +   writel_relaxed(0, (gi2c->base +
> +  SE_GENI_TX_WATERMARK_REG));

The writes to the TX_WATERMARK_REG here and a little further down in
the irq handler stick out to me. A comment as to why poking at the
watermark register is necessary here would be very helpful.

-Evan
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch -mm 3/4] mm, memcg: replace memory.oom_group with policy tunable

2018-01-24 Thread Tejun Heo
Hello, Andrew.

On Wed, Jan 24, 2018 at 02:08:05PM -0800, Andrew Morton wrote:
> Can we please try to narrow the scope of this issue by concentrating on
> the userspace interfaces?  David believes that the mount option and
> memory.oom_group will disappear again in the near future, others
> disagree.

I'm confident that the interface is gonna age fine.

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch -mm 3/4] mm, memcg: replace memory.oom_group with policy tunable

2018-01-24 Thread Andrew Morton
On Wed, 24 Jan 2018 13:44:02 -0800 (PST) David Rientjes  
wrote:

> On Wed, 24 Jan 2018, Michal Hocko wrote:
> 
> > > The current implementation of memory.oom_group is based on top of a 
> > > selection implementation that is broken in three ways I have listed for 
> > > months:
> > 
> > This doesn't lead to anywhere. You are not presenting any new arguments
> > and you are ignoring feedback you have received so far. We have tried
> > really hard. Considering different _independent_ people presented more or
> > less consistent view on these points I think you should deeply
> > reconsider how you take that feedback.
> > 

Please let's remember that people/process issues are unrelated to the
technical desirability of a proposed change.  IOW, assertions along the
lines of "person X is being unreasonable" do little to affect a merge
decision.

> I've responded to each email providing useful feedback on this patchset.  
> I agreed with Tejun about not embedding the oom mechanism into 
> memory.oom_policy.  I was trying to avoid having two files in the mem 
> cgroup v2 filesystem for oom policy and mechanism.  I agreed that 
> delegating the mechanism to the workload would be useful in some cases.  
> I've solicited feedback on any other opinions on how that can be done 
> better, but it appears another tunable is the most convenient way of 
> allowing this behavior to be specified.
> 
> As a result, this would remove patch 3/4 from the series.  Do you have any 
> other feedback regarding the remainder of this patch series before I 
> rebase it?
> 
> I will address the unfair root mem cgroup vs leaf mem cgroup comparison in 
> a separate patchset to fix an issue where any user of oom_score_adj on a 
> system that is not fully containerized gets very unusual, unexpected, and 
> undocumented results.
> 

Can we please try to narrow the scope of this issue by concentrating on
the userspace interfaces?  David believes that the mount option and
memory.oom_group will disappear again in the near future, others
disagree.

What do we do about that?  For example, would it really be a big
problem to continue to support those interfaces in a future iteration
of this feature?  Or is it possible to omit them from this version of
the feature?  Or is it possible to modify them in some fashion so they
will be better compatible with a future iteration of this feature?

I'm OK with merging a probably-partial feature, expecting it to be
enhanced in the future.  What I have a problem with is merging user
interfaces which will be removed or altered in the future.  Please
solve this problem for me.

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch -mm 3/4] mm, memcg: replace memory.oom_group with policy tunable

2018-01-24 Thread David Rientjes
On Wed, 24 Jan 2018, Michal Hocko wrote:

> > The current implementation of memory.oom_group is based on top of a 
> > selection implementation that is broken in three ways I have listed for 
> > months:
> 
> This doesn't lead to anywhere. You are not presenting any new arguments
> and you are ignoring feedback you have received so far. We have tried
> really hard. Considering different _independent_ people presented more or
> less consistent view on these points I think you should deeply
> reconsider how you take that feedback.
> 

I've responded to each email providing useful feedback on this patchset.  
I agreed with Tejun about not embedding the oom mechanism into 
memory.oom_policy.  I was trying to avoid having two files in the mem 
cgroup v2 filesystem for oom policy and mechanism.  I agreed that 
delegating the mechanism to the workload would be useful in some cases.  
I've solicited feedback on any other opinions on how that can be done 
better, but it appears another tunable is the most convenient way of 
allowing this behavior to be specified.

As a result, this would remove patch 3/4 from the series.  Do you have any 
other feedback regarding the remainder of this patch series before I 
rebase it?

I will address the unfair root mem cgroup vs leaf mem cgroup comparison in 
a separate patchset to fix an issue where any user of oom_score_adj on a 
system that is not fully containerized gets very unusual, unexpected, and 
undocumented results.

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 5/7] arm64: kvm: Introduce KVM_ARM_SET_SERROR_ESR ioctl

2018-01-24 Thread gengdongjiu
Hi James,
   Thanks a lot for your review and comments.

> 
> Hi Dongjiu Geng,
> 
> On 06/01/18 16:02, Dongjiu Geng wrote:
> > The ARM64 RAS SError Interrupt(SEI) syndrome value is specific to the
> > guest and user space needs a way to tell KVM this value. So we add a
> > new ioctl. Before user space specifies the Exception Syndrome Register
> > ESR(ESR), it firstly checks that whether KVM has the capability to set
> > the guest ESR, If has, will set it. Otherwise, nothing to do.
> >
> > For this ESR specifying, Only support for AArch64, not support AArch32.
> 
> After this patch user-space can trigger an SError in the guest. If it wants 
> to migrate the guest, how does the pending SError get migrated?
> 
> I think we need to fix migration first. Andrew Jones suggested using
> KVM_GET/SET_VCPU_EVENTS:
> https://www.spinics.net/lists/arm-kernel/msg616846.html
> 
> Given KVM uses kvm_inject_vabt() on v8.0 hardware too, we should cover 
> systems without the v8.2 RAS Extensions with the same API. I
> think this means a bit to read/write whether SError is pending, and another 
> to indicate the ESR should be set/read.
> CPUs without the v8.2 RAS Extensions can reject pending-SError that had an 
> ESR.

For the CPUs without the v8.2 RAS Extensions, its ESR is always 0, we only can 
inject a SError with ESR 0 to guest, cannot set its ESR.
About how about to use the KVM_GET/SET_VCPU_EVENTS, I will check the code, and 
consider your suggestion at the same time. 
The IOCTL KVM_GET/SET_VCPU_EVENTS has been used by X86.

> 
> user-space can then use the 'for migration' calls to make a 'new' SError 
> pending.
> 
> Now that the cpufeature bits are queued, I think this can be split up into 
> two separate series for v4.16-rc1, one to tackle NOTIFY_SEI and
> the associated plumbing. The second for the KVM 'make SError pending' API.

Ok, thanks for your suggestion, will split it.

> 
> 
> > diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index
> > 5c7f657..738ae90 100644
> > --- a/arch/arm64/kvm/guest.c
> > +++ b/arch/arm64/kvm/guest.c
> > @@ -277,6 +277,11 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu 
> > *vcpu,
> > return -EINVAL;
> >  }
> >
> > +int kvm_arm_set_sei_esr(struct kvm_vcpu *vcpu, u32 *syndrome) {
> > +   return -EINVAL;
> > +}
> 
> Does nothing in the patch that adds the support? This is a bit odd.
> (oh, its hiding in patch 6...)

To make this patch simple and small, I add it in patch 6.

> 
> 
> Thanks,
> 
> James

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2 0/5] pktgen: Behavior flags fixes

2018-01-24 Thread David Miller
From: Dmitry Safonov 
Date: Thu, 18 Jan 2018 18:31:32 +

> v2:
>   o fixed a nitpick from David Miller
> 
> There are a bunch of fixes/cleanups/Documentations.
> Diffstat says for itself, regardless added docs and missed flag
> parameters.

Series applied to net-next, thank you.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Documentation: decnet: remove reference to CONFIG_DECNET_ROUTE_FWMARK

2018-01-24 Thread Corentin Labbe
CONFIG_DECNET_ROUTE_FWMARK was removed in commit 47dcf0cb1005 ("[NET]: Rethink 
mark field in struct flowi")
Since nothing replace it (and nothing need to replace it), simply remove
it from documentation.

Signed-off-by: Corentin Labbe 
---
 Documentation/networking/decnet.txt | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Documentation/networking/decnet.txt 
b/Documentation/networking/decnet.txt
index e12a4900cf72..d192f8b9948b 100644
--- a/Documentation/networking/decnet.txt
+++ b/Documentation/networking/decnet.txt
@@ -22,8 +22,6 @@ you'll need the following options as well...
 CONFIG_DECNET_ROUTER (to be able to add/delete routes)
 CONFIG_NETFILTER (will be required for the DECnet routing daemon)
 
-CONFIG_DECNET_ROUTE_FWMARK is optional
-
 Don't turn on SIOCGIFCONF support for DECnet unless you are really sure
 that you need it, in general you won't and it can cause ifconfig to
 malfunction.
-- 
2.13.6

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/3] s390: documentation update

2018-01-24 Thread Sebastian Ott
On Tue, 23 Jan 2018, Cornelia Huck wrote:
> Cornelia Huck (3):
>   s390/docs: mention subchannel types
>   s390/docs: reword airq section
>   s390/cmf: fix kerneldoc

All applied. Thanks!

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] media: cxusb, dib0700: ignore XC2028_I2C_FLUSH

2018-01-24 Thread Mauro Carvalho Chehab
The XC2028_I2C_FLUSH only needs to be implemented on a few
devices. Others can safely ignore it.

That prevents filling the dmesg with lots of messages like:

dib0700: stk7700ph_xc3028_callback: unknown command 2, arg 0

Reported-by: Enrico Mioso 
Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/dvb-usb/cxusb.c   | 2 ++
 drivers/media/usb/dvb-usb/dib0700_devices.c | 1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/media/usb/dvb-usb/cxusb.c 
b/drivers/media/usb/dvb-usb/cxusb.c
index 37dea0adc695..cfe86b4864b3 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -677,6 +677,8 @@ static int dvico_bluebird_xc2028_callback(void *ptr, int 
component,
case XC2028_RESET_CLK:
deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
break;
+   case XC2028_I2C_FLUSH:
+   break;
default:
deb_info("%s: unknown command %d, arg %d\n", __func__,
 command, arg);
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 366b05529915..a9968fb1e8e4 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -430,6 +430,7 @@ static int stk7700ph_xc3028_callback(void *ptr, int 
component,
state->dib7000p_ops.set_gpio(adap->fe_adap[0].fe, 8, 0, 1);
break;
case XC2028_RESET_CLK:
+   case XC2028_I2C_FLUSH:
break;
default:
err("%s: unknown command %d, arg %d\n", __func__,
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] can: migrate documentation to restructured text

2018-01-24 Thread Robert Schwebel
On Wed, Jan 24, 2018 at 12:50:20PM +0100, Marc Kleine-Budde wrote:
> On 01/24/2018 11:19 AM, Robert Schwebel wrote:
> > The kernel documentation is now restructured text. Convert the SocketCAN
> > documentation and include it in the toplevel kernel documentation.
> > 
> > This patch doesn't do any content change.
> > 
> > All references to can.txt in the code are converted to can.rst.
> > 
> > Signed-off-by: Robert Schwebel 
> 
> This fails to apply on next-next/master. v4.15-rc7 was working though
> and git rebase did the work. Use net-next/master as a base in the future.

Thanks, will do.

rsc 
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


signature.asc
Description: PGP signature


Re: [PATCH] can: migrate documentation to restructured text

2018-01-24 Thread Marc Kleine-Budde
On 01/24/2018 11:19 AM, Robert Schwebel wrote:
> The kernel documentation is now restructured text. Convert the SocketCAN
> documentation and include it in the toplevel kernel documentation.
> 
> This patch doesn't do any content change.
> 
> All references to can.txt in the code are converted to can.rst.
> 
> Signed-off-by: Robert Schwebel 

This fails to apply on next-next/master. v4.15-rc7 was working though
and git rebase did the work. Use net-next/master as a base in the future.

> ---
>  .../devicetree/bindings/powerpc/fsl/mpc5200.txt|2 +-
>  Documentation/networking/00-INDEX  |2 -
>  Documentation/networking/can.rst   | 1437 
> 
>  Documentation/networking/can.txt   | 1308 --
>  Documentation/networking/index.rst |1 +
>  MAINTAINERS|2 +-
>  drivers/net/can/dev.c  |2 +-
>  drivers/net/can/vcan.c |2 +-
>  net/can/Kconfig|2 +-
>  9 files changed, 1443 insertions(+), 1315 deletions(-)
>  create mode 100644 Documentation/networking/can.rst
>  delete mode 100644 Documentation/networking/can.txt
> 
> diff --git a/Documentation/devicetree/bindings/powerpc/fsl/mpc5200.txt 
> b/Documentation/devicetree/bindings/powerpc/fsl/mpc5200.txt
> index 4ccb2cd5df94..418d0baae2e9 100644
> --- a/Documentation/devicetree/bindings/powerpc/fsl/mpc5200.txt
> +++ b/Documentation/devicetree/bindings/powerpc/fsl/mpc5200.txt
> @@ -195,4 +195,4 @@ External interrupts:
>  
>  fsl,mpc5200-mscan nodes
>  ---
> -See file can.txt in this directory.
> +See file can.rst in this directory.

This is wrong since a long time. I've fixed this in an individual patch.
Otherwise applied.

Thanks,
Marc

-- 
Pengutronix e.K.  | Marc Kleine-Budde   |
Industrial Linux Solutions| Phone: +49-231-2826-924 |
Vertretung West/Dortmund  | Fax:   +49-5121-206917- |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] can: migrate documentation to restructured text

2018-01-24 Thread Robert Schwebel
On Wed, Jan 24, 2018 at 11:19:11AM +0100, Robert Schwebel wrote:
> This patch doesn't do any content change.

For easier review, here is the 'git diff -w' output that ignores rst
related whitespace changes:

diff --git a/Documentation/networking/can.txt b/Documentation/networking/can.txt
index aa15b9ee2e70..d23c51abf8c6 100644
--- a/Documentation/networking/can.txt
+++ b/Documentation/networking/can.txt
@@ -1,65 +1,9 @@
-
-
-can.txt
-
-Readme file for the Controller Area Network Protocol Family (aka SocketCAN)
-
-This file contains
-
-  1 Overview / What is SocketCAN
-
-  2 Motivation / Why using the socket API
-
-  3 SocketCAN concept
-3.1 receive lists
-3.2 local loopback of sent frames
-3.3 network problem notifications
-
-  4 How to use SocketCAN
-4.1 RAW protocol sockets with can_filters (SOCK_RAW)
-  4.1.1 RAW socket option CAN_RAW_FILTER
-  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
-  4.1.3 RAW socket option CAN_RAW_LOOPBACK
-  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
-  4.1.5 RAW socket option CAN_RAW_FD_FRAMES
-  4.1.6 RAW socket option CAN_RAW_JOIN_FILTERS
-  4.1.7 RAW socket returned message flags
-4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
-  4.2.1 Broadcast Manager operations
-  4.2.2 Broadcast Manager message flags
-  4.2.3 Broadcast Manager transmission timers
-  4.2.4 Broadcast Manager message sequence transmission
-  4.2.5 Broadcast Manager receive filter timers
-  4.2.6 Broadcast Manager multiplex message receive filter
-  4.2.7 Broadcast Manager CAN FD support
-4.3 connected transport protocols (SOCK_SEQPACKET)
-4.4 unconnected transport protocols (SOCK_DGRAM)
-
-  5 SocketCAN core module
-5.1 can.ko module params
-5.2 procfs content
-5.3 writing own CAN protocol modules
-
-  6 CAN network drivers
-6.1 general settings
-6.2 local loopback of sent frames
-6.3 CAN controller hardware filters
-6.4 The virtual CAN driver (vcan)
-6.5 The CAN network device driver interface
-  6.5.1 Netlink interface to set/get devices properties
-  6.5.2 Setting the CAN bit-timing
-  6.5.3 Starting and stopping the CAN network device
-6.6 CAN FD (flexible data rate) driver support
-6.7 supported CAN hardware
-
-  7 SocketCAN resources
-
-  8 Credits
-
-
-
-1. Overview / What is SocketCAN
-
+===
+SocketCAN - Controller Area Network
+===
+
+Overview / What is SocketCAN
+
 
 The socketcan package is an implementation of CAN protocols
 (Controller Area Network) for Linux.  CAN is a networking technology
@@ -72,8 +16,11 @@ as similar as possible to the TCP/IP protocols to allow 
programmers,
 familiar with network programming, to easily learn how to use CAN
 sockets.
 
-2. Motivation / Why using the socket API
-
+
+.. _socketcan-motivation:
+
+Motivation / Why Using the Socket API
+=
 
 There have been CAN implementations for Linux before SocketCAN so the
 question arises, why we have started another project.  Most existing
@@ -116,15 +63,15 @@ Similar functionality visible from user-space could be 
provided by a
 character device, too, but this would lead to a technically inelegant
 solution for a couple of reasons:
 
-* Intricate usage.  Instead of passing a protocol argument to
+* **Intricate usage:**  Instead of passing a protocol argument to
   socket(2) and using bind(2) to select a CAN interface and CAN ID, an
   application would have to do all these operations using ioctl(2)s.
 
-* Code duplication.  A character device cannot make use of the Linux
+* **Code duplication:**  A character device cannot make use of the Linux
   network queueing code, so all that code would have to be duplicated
   for CAN networking.
 
-* Abstraction.  In most existing character-device implementations, the
+* **Abstraction:**  In most existing character-device implementations, the
   hardware-specific device driver for a CAN controller directly
   provides the character device for the application to work with.
   This is at least very unusual in Unix systems for both, char and
@@ -152,10 +99,13 @@ solution for a couple of reasons:
 The use of the networking framework of the Linux kernel is just the
 natural and most appropriate way to implement CAN for Linux.
 
-3. SocketCAN concept
--
 
-  As described in chapter 2 it is the main goal of SocketCAN to
+.. _socketcan-concept:
+
+SocketCAN Concept
+=
+
+As described in :ref:`socketcan-motivation` the main goal of SocketCAN is to
 provide a socket interface to user space applications which builds
 upon the Linux network layer. In contrast to the 

Re: [patch -mm 3/4] mm, memcg: replace memory.oom_group with policy tunable

2018-01-24 Thread Michal Hocko
On Tue 23-01-18 14:22:07, David Rientjes wrote:
> On Tue, 23 Jan 2018, Michal Hocko wrote:
> 
> > > It can't, because the current patchset locks the system into a single 
> > > selection criteria that is unnecessary and the mount option would become 
> > > a 
> > > no-op after the policy per subtree becomes configurable by the user as 
> > > part of the hierarchy itself.
> > 
> > This is simply not true! OOM victim selection has changed in the
> > past and will be always a subject to changes in future. Current
> > implementation doesn't provide any externally controlable selection
> > policy and therefore the default can be assumed. Whatever that default
> > means now or in future. The only contract added here is the kill full
> > memcg if selected and that can be implemented on _any_ selection policy.
> > 
> 
> The current implementation of memory.oom_group is based on top of a 
> selection implementation that is broken in three ways I have listed for 
> months:

This doesn't lead to anywhere. You are not presenting any new arguments
and you are ignoring feedback you have received so far. We have tried
really hard. Considering different _independent_ people presented more or
less consistent view on these points I think you should deeply
reconsider how you take that feedback.

>  - allows users to intentionally/unintentionally evade the oom killer,
>requires not locking the selection implementation for the entire
>system, requires subtree control to prevent, makes a mount option
>obsolete, and breaks existing users who would use the implementation
>based on 4.16 if this were merged,
> 
>  - unfairly compares the root mem cgroup vs leaf mem cgroup such that
>users must structure their hierarchy only for 4.16 in such a way
>that _all_ processes are under hierarchical control and have no
>power to create sub cgroups because of the point above and
>completely breaks any user of oom_score_adj in a completely
>undocumented and unspecified way, such that fixing that breakage
>would also break any existing users who would use the implementation
>based on 4.16 if this were merged, and
> 
>  - does not allow userspace to protect important cgroups, which can be
>built on top.

For the last time. This all can be done on top of the proposed solution
without breaking the proposed user API. I am really _convinced_ that you
underestimate how complex it is to provide a sane selection policy API
and it will take _months_ to settle on something. Existing OOM APIs are
a sad story and I definitly do not want to repeat same mistakes from the
past.
-- 
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html