OSDN Git Service

android-x86/kernel.git
5 years agoANDROID: sdcardfs: fix ->llseek to update upper and lower offset
Daniel Rosenberg [Fri, 10 Mar 2017 05:42:01 +0000 (21:42 -0800)]
ANDROID: sdcardfs: fix ->llseek to update upper and lower offset

Adapted from wrapfs
commit 1d1d23a47baa ("Wrapfs: fix ->llseek to update upper and lower
offsets")

Fixes bug: xfstests generic/257. f_pos consistently is required by and
only by dir_ops->wrapfs_readdir, main_ops is not affected.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Mengyang Li <li.mengyang@stonybrook.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35766959
Change-Id: I360a1368ac37ea8966910a58972b81504031d437

5 years agoANDROID: sdcardfs: copy lower inode attributes in ->ioctl
Daniel Rosenberg [Fri, 10 Mar 2017 05:24:58 +0000 (21:24 -0800)]
ANDROID: sdcardfs: copy lower inode attributes in ->ioctl

Adapted from wrapfs
commit fbc9c6f83ea6 ("Wrapfs: copy lower inode attributes in ->ioctl")
commit e97d8e26cc9e ("Wrapfs: use file_inode helper")

Some ioctls (e.g., EXT2_IOC_SETFLAGS) can change inode attributes, so copy
them from lower inode.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35766959
Change-Id: I0f12684b9dbd4088b4a622c7ea9c03087f40e572

5 years agoANDROID: sdcardfs: remove unnecessary call to do_munmap
Daniel Rosenberg [Fri, 10 Mar 2017 05:14:45 +0000 (21:14 -0800)]
ANDROID: sdcardfs: remove unnecessary call to do_munmap

Adapted from wrapfs
commit 5be6de9ecf02 ("Wrapfs: use vm_munmap in ->mmap")
commit 2c9f6014a8bb ("Wrapfs: remove unnecessary call
to vm_unmap in ->mmap")

Code is unnecessary and causes deadlocks in newer kernels.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35766959
Change-Id: Ia252d60c60799d7e28fc5f1f0f5b5ec2430a2379

5 years agoANDROID: sdcardfs: Fix style issues in macros
Daniel Rosenberg [Wed, 22 Mar 2017 02:11:38 +0000 (19:11 -0700)]
ANDROID: sdcardfs: Fix style issues in macros

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: I89c4035029dc2236081a7685c55cac595d9e7ebf

5 years agoANDROID: sdcardfs: Use seq_puts over seq_printf
Daniel Rosenberg [Wed, 22 Mar 2017 00:27:40 +0000 (17:27 -0700)]
ANDROID: sdcardfs: Use seq_puts over seq_printf

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: I3795ec61ce61e324738815b1ce3b0e09b25d723f

5 years agoANDROID: sdcardfs: Use to kstrout
Daniel Rosenberg [Fri, 17 Mar 2017 02:32:59 +0000 (19:32 -0700)]
ANDROID: sdcardfs: Use to kstrout

Switch from deprecated simple_strtoul to kstrout

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: If18bd133b4d2877f71e58b58fc31371ff6613ed5

5 years agoANDROID: sdcardfs: Use pr_[...] instead of printk
Daniel Rosenberg [Fri, 17 Mar 2017 00:46:13 +0000 (17:46 -0700)]
ANDROID: sdcardfs: Use pr_[...] instead of printk

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: Ibc635ec865750530d32b87067779f681fe58a003

5 years agoANDROID: sdcardfs: remove unneeded null check
Daniel Rosenberg [Tue, 21 Mar 2017 23:29:13 +0000 (16:29 -0700)]
ANDROID: sdcardfs: remove unneeded null check

As pointed out by checkpatch, these functions already
handle null inputs, so the checks are not needed.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: I189342f032dfcefee36b27648bb512488ad61d20

5 years agoANDROID: sdcardfs: Fix style issues with comments
Daniel Rosenberg [Fri, 17 Mar 2017 02:33:35 +0000 (19:33 -0700)]
ANDROID: sdcardfs: Fix style issues with comments

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: I8791ef7eac527645ecb9407908e7e5ece35b8f80

5 years agoANDROID: sdcardfs: Fix formatting
Daniel Rosenberg [Fri, 17 Mar 2017 00:42:58 +0000 (17:42 -0700)]
ANDROID: sdcardfs: Fix formatting

This fixes various spacing and bracket related issues
pointed out by checkpatch.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: I6e248833a7a04e3899f3ae9462d765cfcaa70c96

5 years agoANDROID: sdcardfs: correct order of descriptors
Daniel Rosenberg [Tue, 21 Mar 2017 23:28:27 +0000 (16:28 -0700)]
ANDROID: sdcardfs: correct order of descriptors

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35331000
Change-Id: Ia6d16b19c8c911f41231d2a12be0740057edfacf

5 years agoANDROID: sdcardfs: Fix gid issue
Daniel Rosenberg [Mon, 13 Mar 2017 22:34:03 +0000 (15:34 -0700)]
ANDROID: sdcardfs: Fix gid issue

We were already calculating most of these values,
and erroring out because the check was confused by this.
Instead of recalculating, adjust it as needed.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 36160015
Change-Id: I9caf3e2fd32ca2e37ff8ed71b1d392f1761bc9a9

5 years agoANDROID: sdcardfs: Remove uninformative prints
Daniel Rosenberg [Sat, 11 Mar 2017 02:58:25 +0000 (18:58 -0800)]
ANDROID: sdcardfs: Remove uninformative prints

At best these prints do not provide useful information, and
at worst, some allow userspace to abuse the kernel log.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 36138424
Change-Id: I812c57cc6a22b37262935ab77f48f3af4c36827e

5 years agoANDROID: sdcardfs: move path_put outside of spinlock
Daniel Rosenberg [Fri, 10 Mar 2017 21:54:30 +0000 (13:54 -0800)]
ANDROID: sdcardfs: move path_put outside of spinlock

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35643557
Change-Id: Ib279ebd7dd4e5884d184d67696a93e34993bc1ef

5 years agoANDROID: sdcardfs: Use case insensitive hash function
Daniel Rosenberg [Fri, 10 Mar 2017 20:39:42 +0000 (12:39 -0800)]
ANDROID: sdcardfs: Use case insensitive hash function

Case insensitive comparisons don't help us much if
we hash to different buckets...

Signed-off-by: Daniel Rosenberg <drosen@google.com>
bug: 36004503
Change-Id: I91e00dbcd860a709cbd4f7fd7fc6d855779f3285

5 years agoANDROID: sdcardfs: declare MODULE_ALIAS_FS
Daniel Rosenberg [Fri, 10 Mar 2017 04:59:18 +0000 (20:59 -0800)]
ANDROID: sdcardfs: declare MODULE_ALIAS_FS

From commit ee616b78aa87 ("Wrapfs: declare MODULE_ALIAS_FS")

Signed-off-by: Daniel Rosenberg <drosen@google.com>
bug: 35766959
Change-Id: Ia4728ab49d065b1d2eb27825046f14b97c328cba

5 years agoANDROID: sdcardfs: Get the blocksize from the lower fs
Daniel Rosenberg [Fri, 10 Mar 2017 02:12:16 +0000 (18:12 -0800)]
ANDROID: sdcardfs: Get the blocksize from the lower fs

This changes sdcardfs to be more in line with the
getattr in wrapfs, which calls the lower fs's getattr
to get the block size

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34723223
Change-Id: I1c9e16604ba580a8cdefa17f02dcc489d7351aed

5 years agoANDROID: sdcardfs: Use d_invalidate instead of drop_recurisve
Daniel Rosenberg [Thu, 9 Mar 2017 01:45:46 +0000 (17:45 -0800)]
ANDROID: sdcardfs: Use d_invalidate instead of drop_recurisve

drop_recursive did not properly remove stale dentries.
Instead, we use the vfs's d_invalidate, which does the proper cleanup.

Additionally, remove the no longer used drop_recursive, and
fixup_top_recursive that that are no longer used.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: Ibff61b0c34b725b024a050169047a415bc90f0d8

5 years agoANDROID: sdcardfs: Switch to internal case insensitive compare
Daniel Rosenberg [Thu, 9 Mar 2017 01:20:02 +0000 (17:20 -0800)]
ANDROID: sdcardfs: Switch to internal case insensitive compare

There were still a few places where we called into a case
insensitive lookup that was not defined by sdcardfs.
Moving them all to the same place will allow us to switch
the implementation in the future.

Additionally, the check in fixup_perms_recursive did not
take into account the length of both strings, causing
extraneous matches when the name we were looking for was
a prefix of the child name.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: I45ce768cd782cb4ea1ae183772781387c590ecc2

5 years agoANDROID: sdcardfs: Use spin_lock_nested
Daniel Rosenberg [Thu, 9 Mar 2017 01:11:51 +0000 (17:11 -0800)]
ANDROID: sdcardfs: Use spin_lock_nested

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 36007653
Change-Id: I805d5afec797669679853fb2bb993ee38e6276e4

5 years agoANDROID: sdcardfs: Replace get/put with d_lock
Daniel Rosenberg [Thu, 2 Mar 2017 23:11:27 +0000 (15:11 -0800)]
ANDROID: sdcardfs: Replace get/put with d_lock

dput cannot be called with a spin_lock. Instead,
we protect our accesses by holding the d_lock.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35643557
Change-Id: I22cf30856d75b5616cbb0c223724f5ab866b5114

5 years agoANDROID: sdcardfs: rate limit warning print
Daniel Rosenberg [Fri, 3 Mar 2017 02:07:21 +0000 (18:07 -0800)]
ANDROID: sdcardfs: rate limit warning print

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35848445
Change-Id: Ida72ea0ece191b2ae4a8babae096b2451eb563f6

5 years agoANDROID: sdcardfs: Fix case insensitive lookup
Daniel Rosenberg [Thu, 2 Mar 2017 01:04:41 +0000 (17:04 -0800)]
ANDROID: sdcardfs: Fix case insensitive lookup

The previous case insensitive lookup relied on the
entry being present in the dcache. This instead uses
iterate_dir to find the correct case.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
bug: 35633782
Change-Id: I556f7090773468c1943c89a5e2aa07f746ba49c5

5 years agoANDROID: sdcardfs: support direct-IO (DIO) operations
Daniel Rosenberg [Fri, 24 Feb 2017 23:49:45 +0000 (15:49 -0800)]
ANDROID: sdcardfs: support direct-IO (DIO) operations

This comes from the wrapfs
commit 2e346c83b26e ("Wrapfs: support direct-IO (DIO) operations")

Signed-off-by: Li Mengyang <li.mengyang@stonybrook.edu>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34133558
Change-Id: I3fd779c510ab70d56b1d918f99c20421b524cdc4

5 years agoANDROID: sdcardfs: implement vm_ops->page_mkwrite
Daniel Rosenberg [Fri, 24 Feb 2017 23:41:48 +0000 (15:41 -0800)]
ANDROID: sdcardfs: implement vm_ops->page_mkwrite

This comes from wrapfs
commit 3dfec0ffe5e2 ("Wrapfs: implement vm_ops->page_mkwrite")

Some file systems (e.g., ext4) require it.  Reported by Ted Ts'o.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34133558
Change-Id: I1a389b2422c654a6d3046bb8ec3e20511aebfa8e

5 years agoANDROID: sdcardfs: Don't bother deleting freelist
Daniel Rosenberg [Wed, 22 Feb 2017 22:41:58 +0000 (14:41 -0800)]
ANDROID: sdcardfs: Don't bother deleting freelist

There is no point deleting entries from dlist, as
that is a temporary list on the stack from which
contains only entries that are being deleted.

Not all code paths set up dlist, so those that
don't were performing invalid accesses in
hash_del_rcu. As an additional means to prevent
any other issue, we null out the list entries when
we allocate from the cache.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35666680
Change-Id: Ibb1e28c08c3a600c29418d39ba1c0f3db3bf31e5

5 years agoANDROID: sdcardfs: Add missing path_put
Daniel Rosenberg [Fri, 17 Feb 2017 01:55:22 +0000 (17:55 -0800)]
ANDROID: sdcardfs: Add missing path_put

"ANDROID: sdcardfs: Add GID Derivation to sdcardfs" introduced
an unbalanced pat_get, leading to storage space not being freed
after deleting a file until rebooting. This adds the missing path_put.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34691169
Change-Id: Ia7ef97ec2eca2c555cc06b235715635afc87940e

5 years agoANDROID: sdcardfs: Fix incorrect hash
Daniel Rosenberg [Wed, 15 Feb 2017 04:47:17 +0000 (20:47 -0800)]
ANDROID: sdcardfs: Fix incorrect hash

This adds back the hash calculation removed as part of
the previous patch, as it is in fact necessary.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35307857
Change-Id: Ie607332bcf2c5d2efdf924e4060ef3f576bf25dc

5 years agoANDROID: sdcardfs: Switch strcasecmp for internal call
Daniel Rosenberg [Wed, 1 Feb 2017 04:07:51 +0000 (20:07 -0800)]
ANDROID: sdcardfs: Switch strcasecmp for internal call

This moves our uses of strcasecmp over to an internal call so we can
easily change implementations later if we so desire. Additionally,
we leverage qstr's where appropriate to save time on comparisons.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: I32fdc4fd0cd3b7b735dcfd82f60a2516fd8272a5

5 years agoANDROID: sdcardfs: switch to full_name_hash and qstr
Daniel Rosenberg [Sat, 28 Jan 2017 03:35:08 +0000 (19:35 -0800)]
ANDROID: sdcardfs: switch to full_name_hash and qstr

Use the kernel's string hash function instead of rolling
our own. Additionally, save a bit of calculation by using
the qstr struct in place of strings.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: I0bbeb5ec2a9233f40135ad632e6f22c30ffa95c1

5 years agoANDROID: sdcardfs: Add GID Derivation to sdcardfs
Daniel Rosenberg [Wed, 25 Jan 2017 21:48:45 +0000 (13:48 -0800)]
ANDROID: sdcardfs: Add GID Derivation to sdcardfs

This changes sdcardfs to modify the user and group in the
underlying filesystem depending on its usage. Ownership is
set by Android user, and package, as well as if the file is
under obb or cache. Other files can be labeled by extension.
Those values are set via the configfs interace.

To add an entry,
mkdir -p [configfs root]/sdcardfs/extensions/[gid]/[ext]

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34262585
Change-Id: I4e030ce84f094a678376349b1a96923e5076a0f4

5 years agoANDROID: sdcardfs: Remove redundant operation
Daniel Rosenberg [Fri, 27 Jan 2017 04:10:34 +0000 (20:10 -0800)]
ANDROID: sdcardfs: Remove redundant operation

We call get_derived_permission_new unconditionally, so we don't need
to call update_derived_permission_lock, which does the same thing.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: I0748100828c6af806da807241a33bf42be614935

5 years agoANDROID: sdcardfs: add support for user permission isolation
Daniel Rosenberg [Sun, 22 Jan 2017 23:32:49 +0000 (15:32 -0800)]
ANDROID: sdcardfs: add support for user permission isolation

This allows you to hide the existence of a package from
a user by adding them to an exclude list. If a user
creates that package's folder and is on the exclude list,
they will not see that package's id.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34542611
Change-Id: I9eb82e0bf2457d7eb81ee56153b9c7d2f6646323

5 years agoANDROID: sdcardfs: Refactor configfs interface
Daniel Rosenberg [Sat, 21 Jan 2017 08:35:26 +0000 (00:35 -0800)]
ANDROID: sdcardfs: Refactor configfs interface

This refactors the configfs code to be more easily extended.
It will allow additional files to be added easily.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 34542611
Bug: 34262585
Change-Id: I73c9b0ae5ca7eb27f4ebef3e6807f088b512d539

5 years agoANDROID: sdcardfs: Allow non-owners to touch
Daniel Rosenberg [Fri, 20 Jan 2017 23:19:13 +0000 (15:19 -0800)]
ANDROID: sdcardfs: Allow non-owners to touch

This modifies the permission checks in setattr to
allow for non-owners to modify the timestamp of
files to things other than the current time.
This still requires write access, as enforced by
the permission call, but relaxes the requirement
that the caller must be the owner, allowing those
with group permissions to change it as well.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 11118565
Change-Id: Ied31f0cce2797675c7ef179eeb4e088185adcbad

5 years agoANDROID: sdcardfs: eliminate the offset argument to ->direct_IO
Amit Pundir [Tue, 7 Jun 2016 11:00:56 +0000 (16:30 +0530)]
ANDROID: sdcardfs: eliminate the offset argument to ->direct_IO

Eliminate the offset argument to sdcardfs_direct_IO() which is dropped
by upstream commit c8b8e32d700f ("direct-io: eliminate the offset
argument to ->direct_IO"), otherwise we run into following build error:

  CC [M]  fs/sdcardfs/mmap.o
fs/sdcardfs/mmap.c:76:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .direct_IO = sdcardfs_direct_IO,
               ^
fs/sdcardfs/mmap.c:76:15: note: (near initialization for ‘sdcardfs_aops.direct_IO’)

Change-Id: I292d93bb16365a9fa46494accb2b5da51028b5c1
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: sdcardfs: make it use new .rename i_op
Amit Pundir [Sun, 16 Oct 2016 09:54:15 +0000 (15:24 +0530)]
ANDROID: sdcardfs: make it use new .rename i_op

Since commit 2773bf00aeb9 ("fs: rename "rename2" i_op to "rename""),
syscall rename2 is merged with rename syscall and it broke sdcard_fs
build and we get following build error:

  CC [M]  fs/sdcardfs/inode.o
fs/sdcardfs/inode.c:786:13: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .rename  = sdcardfs_rename,
             ^
fs/sdcardfs/inode.c:786:13: note: (near initialization for ‘sdcardfs_dir_iops.rename’)

renameat2 syscall is the same as renameat with an added flags argument
and calling renameat2 with flags=0 is equivalent to calling renameat.

Change-Id: I48f3c76c3af481241188253a76f310670de6bd18
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: sdcardfs: Propagate dentry down to inode_change_ok()
Amit Pundir [Tue, 11 Oct 2016 07:56:17 +0000 (13:26 +0530)]
ANDROID: sdcardfs: Propagate dentry down to inode_change_ok()

Since commit 31051c85b5e2 ("fs: Give dentry to inode_change_ok()
instead of inode"), to avoid clearing of capabilities or security
related extended attributes too early, inode_change_ok() will
need to take dentry instead of inode. Propagate it down to
sdcardfs_setattr() and also rename it to setattr_prepare(),
otherwise we run into following build error:

  CC [M]  fs/sdcardfs/inode.o
fs/sdcardfs/inode.c: In function ‘sdcardfs_setattr’:
fs/sdcardfs/inode.c:644:8: error: implicit declaration of function ‘inode_change_ok’ [-Werror=implicit-function-declaration]
  err = inode_change_ok(inode, ia);
        ^

Change-Id: I714b4f4f68b7fea1ac82a71d2f323c76b11fa008
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: sdcardfs: get rid of 'parent' argument of ->d_compare()
Amit Pundir [Mon, 8 Aug 2016 06:57:33 +0000 (12:27 +0530)]
ANDROID: sdcardfs: get rid of 'parent' argument of ->d_compare()

->d_compare() doesn't get parent as a separate argument anymore
according to upstream commit 6fa67e707559 ("get rid of 'parent'
argument of ->d_compare()").

We run into following build error otherwise:

  CC [M]  fs/sdcardfs/dentry.o
fs/sdcardfs/dentry.c:183:15: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
  .d_compare = sdcardfs_cmp_ci,
               ^
fs/sdcardfs/dentry.c:183:15: note: (near initialization for ‘sdcardfs_ci_dops.d_compare’)

Change-Id: I51801b57aeb8287f1e69ce6cb944e8722ff37bea
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: sdcardfs: add parent pointer into dentry name hash
Amit Pundir [Thu, 4 Aug 2016 15:34:31 +0000 (21:04 +0530)]
ANDROID: sdcardfs: add parent pointer into dentry name hash

Fix following sdcardfs compilation error introduced in code
refactoring by upstream commit 8387ff2577eb ("vfs: make the
string hashes salt the hash").

  CC [M]  fs/sdcardfs/dentry.o
In file included from ./include/linux/dcache.h:13:0,
                 from fs/sdcardfs/sdcardfs.h:29,
                 from fs/sdcardfs/dentry.c:21:
fs/sdcardfs/dentry.c: In function ‘sdcardfs_hash_ci’:
./include/linux/stringhash.h:38:51: error: expected expression before ‘)’ token
 #define init_name_hash(salt)  (unsigned long)(salt)
                                                   ^
fs/sdcardfs/dentry.c:138:9: note: in expansion of macro ‘init_name_hash’
  hash = init_name_hash();
         ^

Change-Id: I9feb6c075a7e953726954f5746fc009202d3121c
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: sdcardfs: use wrappers to access i_mutex
Amit Pundir [Wed, 1 Jun 2016 16:23:20 +0000 (21:53 +0530)]
ANDROID: sdcardfs: use wrappers to access i_mutex

Use inode_{lock,unlock,lock_nested} wrappers as suggested by upstream
commit 5955102c9984 (wrappers for ->i_mutex access) for access to
->i_mutex, otherwise we run into following build error:

  CC [M]  fs/sdcardfs/dentry.o
In file included from fs/sdcardfs/dentry.c:21:0:
fs/sdcardfs/sdcardfs.h: In function ‘lock_parent’:
fs/sdcardfs/sdcardfs.h:422:33: error: ‘struct inode’ has no member named ‘i_mutex’
  mutex_lock_nested(&d_inode(dir)->i_mutex, I_MUTEX_PARENT);
                                 ^
fs/sdcardfs/sdcardfs.h: In function ‘unlock_dir’:
fs/sdcardfs/sdcardfs.h:428:28: error: ‘struct inode’ has no member named ‘i_mutex’
  mutex_unlock(&d_inode(dir)->i_mutex);
                            ^
In file included from ./include/linux/fs.h:19:0,
                 from fs/sdcardfs/sdcardfs.h:31,
                 from fs/sdcardfs/dentry.c:21:
fs/sdcardfs/sdcardfs.h: In function ‘prepare_dir’:
fs/sdcardfs/sdcardfs.h:457:27: error: ‘struct inode’ has no member named ‘i_mutex’
  mutex_lock(&d_inode(dent)->i_mutex);
                           ^
./include/linux/mutex.h:146:44: note: in definition of macro ‘mutex_lock’
 #define mutex_lock(lock) mutex_lock_nested(lock, 0)
                                            ^
In file included from fs/sdcardfs/dentry.c:21:0:
fs/sdcardfs/sdcardfs.h:459:29: error: ‘struct inode’ has no member named‘i_mutex’
  mutex_unlock(&d_inode(dent)->i_mutex);
                             ^
fs/sdcardfs/sdcardfs.h:466:38: error: ‘struct inode’ has no member named ‘i_mutex’
  mutex_unlock(&d_inode(parent.dentry)->i_mutex);
                                      ^

Change-Id: I4c8298045ac511aba5542d9ca967331f550376a5
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: sdcardfs: Fix locking issue with permision fix up
Daniel Rosenberg [Tue, 27 Dec 2016 20:36:29 +0000 (12:36 -0800)]
ANDROID: sdcardfs: Fix locking issue with permision fix up

Don't use lookup_one_len so we can grab the spinlock that
protects d_subdirs.

Bug: 30954918
Change-Id: I0c6a393252db7beb467e0d563739a3a14e1b5115
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Switch ->d_inode to d_inode()
Daniel Rosenberg [Thu, 1 Dec 2016 22:36:29 +0000 (14:36 -0800)]
ANDROID: sdcardfs: Switch ->d_inode to d_inode()

Change-Id: I12375cc2d6e82fb8adf0319be971f335f8d7a312
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Change magic value
Daniel Rosenberg [Tue, 15 Nov 2016 21:35:18 +0000 (13:35 -0800)]
ANDROID: sdcardfs: Change magic value

Sdcardfs uses the same magic value as wrapfs.
This should not be the case. As it is entirely
in memory, the value can be changed without any
loss of compatibility.

Change-Id: I24200b805d5e6d32702638be99e47d50d7f2f746
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Use per mount permissions
Daniel Rosenberg [Thu, 27 Oct 2016 03:27:20 +0000 (20:27 -0700)]
ANDROID: sdcardfs: Use per mount permissions

This switches sdcardfs over to using permission2.
Instead of mounting several sdcardfs instances onto
the same underlaying directory, you bind mount a
single mount several times, and remount with the
options you want. These are stored in the private
mount data, allowing you to maintain the same tree,
but have different permissions for different mount
points.

Warning functions have been added for permission,
as it should never be called, and the correct
behavior is unclear.

Change-Id: I841b1d70ec60cf2b866fa48edeb74a0b0f8334f5
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Add gid and mask to private mount data
Daniel Rosenberg [Thu, 27 Oct 2016 00:36:05 +0000 (17:36 -0700)]
ANDROID: sdcardfs: Add gid and mask to private mount data

Adds support for mount2, remount2, and the functions
to allocate/clone/copy the private data

The next patch will switch over to actually using it.

Change-Id: I8a43da26021d33401f655f0b2784ead161c575e3
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: User new permission2 functions
Daniel Rosenberg [Wed, 26 Oct 2016 23:48:45 +0000 (16:48 -0700)]
ANDROID: sdcardfs: User new permission2 functions

Change-Id: Ic7e0fb8fdcebb31e657b079fe02ac834c4a50db9
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Move directory unlock before touch
Daniel Rosenberg [Mon, 26 Sep 2016 21:48:22 +0000 (14:48 -0700)]
ANDROID: sdcardfs: Move directory unlock before touch

This removes a deadlock under low memory conditions.
filp_open can call lookup_slow, which will attempt to
lock the parent.

Change-Id: I940643d0793f5051d1e79a56f4da2fa8ca3d8ff7
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: fix external storage exporting incorrect uid
alvin_liang [Mon, 19 Sep 2016 08:59:12 +0000 (16:59 +0800)]
ANDROID: sdcardfs: fix external storage exporting incorrect uid

Symptom: App cannot write into per-app folder
Root Cause: sdcardfs exports incorrect uid
Solution: fix uid
Project: All
Note:
Test done by RD: passed

Change-Id: Iff64f6f40ba4c679f07f4426d3db6e6d0db7e3ca

5 years agoANDROID: sdcardfs: Added top to sdcardfs_inode_info
Daniel Rosenberg [Wed, 18 May 2016 23:57:10 +0000 (16:57 -0700)]
ANDROID: sdcardfs: Added top to sdcardfs_inode_info

Adding packages to the package list and moving files
takes a large amount of locks, and is currently a
heavy operation. This adds a 'top' field to the
inode_info, which points to the inode for the top
most directory whose owner you would like to match.

On permission checks and get_attr, we look up the
owner based on the information at top. When we change
a package mapping, we need only modify the information
in the corresponding top inode_info's. When renaming,
we must ensure top is set correctly in all children.
This happens when an app specific folder gets moved
outside of the folder for that app.

Change-Id: Ib749c60b568e9a45a46f8ceed985c1338246ec6c
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Switch package list to RCU
Daniel Rosenberg [Tue, 10 May 2016 20:42:43 +0000 (13:42 -0700)]
ANDROID: sdcardfs: Switch package list to RCU

Switched the package id hashmap to use RCU.

Change-Id: I9fdcab279009005bf28536247d11e13babab0b93
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Fix locking for permission fix up
Daniel Rosenberg [Tue, 16 Aug 2016 22:19:26 +0000 (15:19 -0700)]
ANDROID: sdcardfs: Fix locking for permission fix up

Iterating over d_subdirs requires taking d_lock.
Removed several unneeded locks.

Change-Id: I5b1588e54c7e6ee19b756d6705171c7f829e2650
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Check for other cases on path lookup
Daniel Rosenberg [Wed, 27 Apr 2016 22:31:29 +0000 (15:31 -0700)]
ANDROID: sdcardfs: Check for other cases on path lookup

This fixes a bug where the first lookup of a
file or folder created under a different view
would not be case insensitive. It will now
search through for a case insensitive match
if the initial lookup fails.

Bug:28024488
Change-Id: I4ff9ce297b9f2f9864b47540e740fd491c545229
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: override umask on mkdir and create
Daniel Rosenberg [Wed, 13 Apr 2016 23:38:34 +0000 (16:38 -0700)]
ANDROID: sdcardfs: override umask on mkdir and create

The mode on files created on the lower fs should
not be affected by the umask of the calling
task's fs_struct. Instead, we create a copy
and modify it as needed. This also lets us avoid
the string shenanigans around .nomedia files.

Bug: 27992761
Change-Id: Ia3a6e56c24c6e19b3b01c1827e46403bb71c2f4c
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: fix itnull.cocci warnings
Julia Lawall [Wed, 1 Jun 2016 17:28:49 +0000 (10:28 -0700)]
ANDROID: sdcardfs: fix itnull.cocci warnings

List_for_each_entry has the property that the first argument is always
bound to a real list element, never NULL, so testing dentry is not needed.

Generated by: scripts/coccinelle/iterators/itnull.cocci

Cc: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Guenter Roeck <groeck@chromium.org>
5 years agoANDROID: sdcardfs: Truncate packages_gid.list on overflow
Daniel Rosenberg [Fri, 8 Jul 2016 21:15:14 +0000 (14:15 -0700)]
ANDROID: sdcardfs: Truncate packages_gid.list on overflow

packages_gid.list was improperly returning the wrong
count. Use scnprintf instead, and inform the user that
the list was truncated if it is.

Bug: 30013843
Change-Id: Ida2b2ef7cd86dd87300bfb4c2cdb6bfe2ee1650d
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: remove unneeded __init and __exit
Daniel Rosenberg [Mon, 28 Mar 2016 23:00:34 +0000 (16:00 -0700)]
ANDROID: sdcardfs: remove unneeded __init and __exit

Change-Id: I2a2d45d52f891332174c3000e8681c5167c1564f

5 years agoANDROID: sdcardfs: Remove unused code
Daniel Rosenberg [Mon, 28 Mar 2016 22:00:20 +0000 (15:00 -0700)]
ANDROID: sdcardfs: Remove unused code

Change-Id: Ie97cba27ce44818ac56cfe40954f164ad44eccf6

5 years agoANDROID: sdcardfs: remove effectless config option
Daniel Rosenberg [Wed, 23 Mar 2016 23:39:30 +0000 (16:39 -0700)]
ANDROID: sdcardfs: remove effectless config option

CONFIG_SDCARD_FS_CI_SEARCH only guards a define for
LOOKUP_CASE_INSENSITIVE, which is never used in the
kernel. Remove both, along with the option matching
that supports it.

Change-Id: I363a8f31de8ee7a7a934d75300cc9ba8176e2edf
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Add support for d_canonical_path
Daniel Rosenberg [Fri, 12 Feb 2016 00:53:36 +0000 (16:53 -0800)]
ANDROID: sdcardfs: Add support for d_canonical_path

Change-Id: I5d6f0e71b8ca99aec4b0894412f1dfd1cfe12add
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: sdcardfs: Bring up to date with Android M permissions:
Daniel Rosenberg [Thu, 4 Feb 2016 05:08:21 +0000 (21:08 -0800)]
ANDROID: sdcardfs: Bring up to date with Android M permissions:

In M, the workings of sdcardfs were changed significantly.
This brings sdcardfs into line with the changes.

Change-Id: I10e91a84a884c838feef7aa26c0a2b21f02e052e

5 years agoANDROID: Changed type-casting in packagelist management
Daniel Campello [Mon, 20 Jul 2015 23:33:46 +0000 (16:33 -0700)]
ANDROID: Changed type-casting in packagelist management

Fixed existing type-casting in packagelist management code. All
warnings at compile time were taken care of.

Change-Id: I1ea97786d1d1325f31b9f09ae966af1f896a2af5
Signed-off-by: Daniel Campello <campello@google.com>
5 years agoANDROID: Port of sdcardfs to 4.4
Daniel Campello [Mon, 20 Jul 2015 23:27:37 +0000 (16:27 -0700)]
ANDROID: Port of sdcardfs to 4.4

Change-Id: I25b99ecf214e72ebf6a57ec3085972542a8d7951
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: xattr: Pass EOPNOTSUPP to permission2
Daniel Rosenberg [Tue, 23 Jan 2018 22:34:38 +0000 (14:34 -0800)]
ANDROID: xattr: Pass EOPNOTSUPP to permission2

The permission call for xattr operations happens regardless of
whether or not the xattr functions are implemented.

The xattr functions currently don't have support for permission2.
Passing EOPNOTSUPP as the mount point in xattr_permission allows
us to return EOPNOTSUPP early in permission2, if the filesystem
supports it.

Change-Id: I9d07e4cd633cf40af60450ffbff7ac5c1b4e8c2c
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35848445

5 years agoRFC: ANDROID: vfs: Add permission2 for filesystems with per mount permissions
Daniel Rosenberg [Wed, 26 Oct 2016 23:27:45 +0000 (16:27 -0700)]
RFC: ANDROID: vfs: Add permission2 for filesystems with per mount permissions

This allows filesystems to use their mount private data to
influence the permssions they return in permission2. It has
been separated into a new call to avoid disrupting current
permission users.

Change-Id: I9d416e3b8b6eca84ef3e336bd2af89ddd51df6ca
Signed-off-by: Daniel Rosenberg <drosen@google.com>
[AmitP: Minor refactoring of original patch to align with
        changes from the following upstream commit
        4bfd054ae11e ("fs: fold __inode_permission() into inode_permission()").

        Also introduce vfs_mkobj2(), because do_create()
        moved from using vfs_create() to vfs_mkobj()
        eecec19d9e70 ("mqueue: switch to vfs_mkobj(), quit abusing ->d_fsdata")

        do_create() is dropped/cleaned up upstream so a
        minor refactoring there as well.
        066cc813e94a ("do_mq_open(): move all work prior to dentry_open() into a helper")]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: vfs: Add setattr2 for filesystems with per mount permissions
Daniel Rosenberg [Wed, 26 Oct 2016 23:33:11 +0000 (16:33 -0700)]
ANDROID: vfs: Add setattr2 for filesystems with per mount permissions

This allows filesystems to use their mount private data to
influence the permssions they use in setattr2. It has
been separated into a new call to avoid disrupting current
setattr users.

Change-Id: I19959038309284448f1b7f232d579674ef546385
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: vfs: Allow filesystems to access their private mount data
Daniel Rosenberg [Wed, 26 Oct 2016 22:58:22 +0000 (15:58 -0700)]
ANDROID: vfs: Allow filesystems to access their private mount data

Now we pass the vfsmount when mounting and remounting.
This allows the filesystem to actually set up the mount
specific data, although we can't quite do anything with
it yet. show_options is expanded to include data that
lives with the mount.

To avoid changing existing filesystems, these have
been added as new vfs functions.

Change-Id: If80670bfad9f287abb8ac22457e1b034c9697097
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: fuse: Add support for d_canonical_path
Daniel Rosenberg [Fri, 22 Apr 2016 07:00:48 +0000 (00:00 -0700)]
ANDROID: fuse: Add support for d_canonical_path

Allows FUSE to report to inotify that it is acting
as a layered filesystem. The userspace component
returns a string representing the location of the
underlying file. If the string cannot be resolved
into a path, the top level path is returned instead.

bug: 23904372
Change-Id: Iabdca0bbedfbff59e9c820c58636a68ef9683d9f
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: mnt: Add filesystem private data to mount points
Daniel Rosenberg [Wed, 26 Oct 2016 22:29:51 +0000 (15:29 -0700)]
ANDROID: mnt: Add filesystem private data to mount points

This starts to add private data associated directly
to mount points. The intent is to give filesystems
a sense of where they have come from, as a means of
letting a filesystem take different actions based on
this information.

Change-Id: Ie769d7b3bb2f5972afe05c1bf16cf88c91647ab2
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: vfs: add d_canonical_path for stacked filesystem support
Daniel Rosenberg [Fri, 12 Feb 2016 00:44:15 +0000 (16:44 -0800)]
ANDROID: vfs: add d_canonical_path for stacked filesystem support

Inotify does not currently know when a filesystem
is acting as a wrapper around another fs. This means
that inotify watchers will miss any modifications to
the base file, as well as any made in a separate
stacked fs that points to the same file.
d_canonical_path solves this problem by allowing the fs
to map a dentry to a path in the lower fs. Inotify
can use it to find the appropriate place to watch to
be informed of all changes to a file.

Change-Id: I09563baffad1711a045e45c1bd0bd8713c2cc0b6
Signed-off-by: Daniel Rosenberg <drosen@google.com>
5 years agoANDROID: Included sdcardfs source code for kernel 3.0
Daniel Campello [Mon, 20 Jul 2015 23:23:50 +0000 (16:23 -0700)]
ANDROID: Included sdcardfs source code for kernel 3.0

Only included the source code as is for kernel 3.0. Following patches
take care of porting this file system to version 3.10.

Change-Id: I09e76db77cd98a059053ba5b6fd88572a4b75b5b
Signed-off-by: Daniel Campello <campello@google.com>
5 years agoANDROID: Fix script to fetch android kernel config fragments for 4.14
Dmitry Shmidt [Wed, 24 Jan 2018 21:59:50 +0000 (13:59 -0800)]
ANDROID: Fix script to fetch android kernel config fragments for 4.14

Change-Id: I6036d0cc9d4f28f0df0e8d3267034b34ec276a08
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
5 years agoANDROID: uid_sys_stats: fix the comment
Artem Borisov [Sat, 13 Jan 2018 15:03:40 +0000 (18:03 +0300)]
ANDROID: uid_sys_stats: fix the comment

It is not uid_cputime.c anymore.

Change-Id: I7effc2a449c1f9cba9d86a7b122a9c05fc266405
Signed-off-by: Artem Borisov <dedsa2002@gmail.com>
5 years agoANDROID: netfilter: xt_qtaguid: Fix 4.14 compilation
Dmitry Shmidt [Mon, 8 Jan 2018 23:21:57 +0000 (15:21 -0800)]
ANDROID: netfilter: xt_qtaguid: Fix 4.14 compilation

struct xt_action_param was changed:
  in, out, family and hooknum were moved to
struct nf_hook_state *state
  in, out, pf and hook
Replace atomic_read() with refcount_read()

Change-Id: If463bf84db08fe382baa825ca7818cab2150b60d
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
5 years agoANDROID: initramfs: call free_initrd() when skipping init
Nick Bray [Thu, 30 Nov 2017 23:49:54 +0000 (15:49 -0800)]
ANDROID: initramfs: call free_initrd() when skipping init

Memory allocated for initrd would not be reclaimed if initializing ramfs
was skipped.

Bug: 69901741
Test: "grep MemTotal /proc/meminfo" increases by a few MB on an Android
device with a/b boot.

Change-Id: Ifbe094d303ed12cfd6de6aa004a8a19137a2f58a
Signed-off-by: Nick Bray <ncbray@google.com>
5 years agoANDROID: Revert "arm64: move ELF_ET_DYN_BASE to 4GB / 4MB"
Evgenii Stepanov [Wed, 1 Nov 2017 22:10:12 +0000 (15:10 -0700)]
ANDROID: Revert "arm64: move ELF_ET_DYN_BASE to 4GB / 4MB"

Part of the above change was reverted in c715b72c1ba406f133217b509044c38d8e714a37;
this change reverts the rest.

This ARM mmap change breaks AddressSanitizer:

Shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING.

Revert it until ASAN runtime library is updated to handle it.

Bug: 67425063

Signed-off-by: Evgenii Stepanov <eugenis@google.com>
[AmitP: Updated the commit ID of the upstream commit]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: Revert "arm: move ELF_ET_DYN_BASE to 4MB"
Evgenii Stepanov [Wed, 1 Nov 2017 22:04:42 +0000 (15:04 -0700)]
ANDROID: Revert "arm: move ELF_ET_DYN_BASE to 4MB"

This ARM mmap change breaks AddressSanitizer:

Shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING.

Revert it until ASAN runtime library is updated to handle it.

Bug: 67425063

This reverts commit 6a9af90a3bcde217a1c053e135f5f43e5d5fafbd.

Signed-off-by: Evgenii Stepanov <eugenis@google.com>
[AmitP: Updated the commit ID of reverted upstream commit]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: memory_state_time: fix undefined behavior with missing DT properties
Arnd Bergmann [Wed, 10 May 2017 09:21:27 +0000 (11:21 +0200)]
ANDROID: memory_state_time: fix undefined behavior with missing DT properties

kernelci reports warnings about unintialized variable usage:

drivers/misc/memory_state_time.c:351:12: warning: 'lenf' is used uninitialized in this function [-Wuninitialized]
drivers/misc/memory_state_time.c:321:14: warning: 'lenb' is used uninitialized in this function [-Wuninitialized]

In both cases we try to continue without a DT property but use the
length that has not been assigned at this point. This rearranges the
code in the two functions to bail out earlier in case of an error.

The patch is needed for both android-common-4.9, 4.4 and 3.18.

Link: https://kernelci.org/build/id/591177f459b5147648b12d54/logs/
Fixes: ad3c02f8b3a5 ("ANDROID: Implement memory_state_time, used by qcom,cpubw")
Cc: James Carr <carrja@google.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
5 years agoANDROID: memory_state_time: Implement memory_state_time, used by qcom,cpubw
James Carr [Sat, 30 Jul 2016 02:02:16 +0000 (19:02 -0700)]
ANDROID: memory_state_time: Implement memory_state_time, used by qcom,cpubw

New driver memory_state_time tracks time spent in different DDR
frequency and bandwidth states.

Memory drivers such as qcom,cpubw can post updated state to the driver
after registering a callback. Processed by a workqueue

Bandwidth buckets are read in from device tree in the relevant qualcomm
section, can be defined in any quantity and spacing.

The data is exposed at /sys/kernel/memory_state_time, able to be read by
the Android framework.

Functionality is behind a config option CONFIG_MEMORY_STATE_TIME

Change-Id: I4fee165571cb975fb9eacbc9aada5e6d7dd748f0
Signed-off-by: James Carr <carrja@google.com>
5 years agoANDROID: uid_sys_stats: log task io with a debug flag
Yang Jin [Wed, 26 Jul 2017 19:52:22 +0000 (12:52 -0700)]
ANDROID: uid_sys_stats: log task io with a debug flag

Add a hashmap inside each uid_entry to keep track of task name and io.
Task full name is a combination of thread and process name.

Bug: 63739275
Change-Id: I30083b757eaef8c61e55a213a883ce8d0c9cf2b1
Signed-off-by: Yang Jin <yajin@google.com>
[AmitP: Folded following android-4.9 commit changes into this patch
        0ea205a6a224 ("ANDROID: uid_sys_stats: Fix implicit declaration of get_cmdline()")]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: uid_sys_stats: check previous uid_entry before call find_or_register_uid
Ganesh Mahendran [Thu, 25 May 2017 07:20:29 +0000 (15:20 +0800)]
ANDROID: uid_sys_stats: check previous uid_entry before call find_or_register_uid

Theads in a process are stored in list struct task_struct->thread_group,
so it will be visited continiously in below loop:
do_each_thread(temp, task) {
    ...
} while_each_thread(temp, task);

I add some log in the loop, we can see below information:
[   65.033561] uid 1000, uid_entry ffffffc0f2761600
[   65.033567] uid 1000, uid_entry ffffffc0f2761600
[   65.033574] uid 1000, uid_entry ffffffc0f2761600
[   65.033581] uid 1000, uid_entry ffffffc0f2761600
[   65.033588] uid 1000, uid_entry ffffffc0f2761600
[   65.033595] uid 1000, uid_entry ffffffc0f2761600
[   65.033602] uid 1000, uid_entry ffffffc0f2761600
[   65.033609] uid 1000, uid_entry ffffffc0f2761600
[   65.033615] uid 1000, uid_entry ffffffc0f2761600
[   65.033622] uid 1000, uid_entry ffffffc0f2761600
[   65.033629] uid 1000, uid_entry ffffffc0f2761600
[   65.033637] uid 1000, uid_entry ffffffc0f2761600
[   65.033644] uid 1000, uid_entry ffffffc0f2761600
[   65.033651] uid 1000, uid_entry ffffffc0f2761600
[   65.033658] uid 1000, uid_entry ffffffc0f2761600
[   65.033665] uid 1000, uid_entry ffffffc0f2761600
[   65.033672] uid 1000, uid_entry ffffffc0f2761600
[   65.033680] uid 1000, uid_entry ffffffc0f2761600
[   65.033687] uid 1000, uid_entry ffffffc0f2761600
[   65.033694] uid 1000, uid_entry ffffffc0f2761600
[   65.033701] uid 1000, uid_entry ffffffc0f2761600
[   65.033708] uid 1000, uid_entry ffffffc0f2761600
[   65.033715] uid 1000, uid_entry ffffffc0f2761600
[   65.033722] uid 1000, uid_entry ffffffc0f2761600
[   65.033729] uid 1000, uid_entry ffffffc0f2761600
[   65.033736] uid 1000, uid_entry ffffffc0f2761600
[   65.033743] uid 1000, uid_entry ffffffc0f2761600
[   65.033750] uid 1000, uid_entry ffffffc0f2761600
[   65.033757] uid 1000, uid_entry ffffffc0f2761600
[   65.033763] uid 1000, uid_entry ffffffc0f2761600
[   65.033770] uid 1000, uid_entry ffffffc0f2761600
[   65.033777] uid 1000, uid_entry ffffffc0f2761600
[   65.033784] uid 1000, uid_entry ffffffc0f2761600
[   65.033791] uid 1000, uid_entry ffffffc0f2761600
[   65.033798] uid 1000, uid_entry ffffffc0f2761600

So we can check the previous uid_entry before calling find_or_register_uid
to save time.

Change-Id: I05ec1a1405a80c0a620cb4b4b2f6483dbfde7829
Signed-off-by: Ganesh Mahendran <opensource.ganesh@gmail.com>
5 years agoANDROID: uid_sys_stats: Kconfig: add depends for UID_SYS_STATS
Ganesh Mahendran [Wed, 24 May 2017 02:28:27 +0000 (10:28 +0800)]
ANDROID: uid_sys_stats: Kconfig: add depends for UID_SYS_STATS

uid_io depends on TASK_XACCT and TASK_IO_ACCOUNTING.
So add depends in Kconfig before compiling code.

Change-Id: Ie6bf57ec7c2eceffadf4da0fc2aca001ce10c36e
Signed-off-by: Ganesh Mahendran <opensource.ganesh@gmail.com>
5 years agoANDROID: uid_sys_stats: defer io stats calulation for dead tasks
Jin Qian [Mon, 22 May 2017 19:08:06 +0000 (12:08 -0700)]
ANDROID: uid_sys_stats: defer io stats calulation for dead tasks

Store sum of dead task io stats in uid_entry and defer uid io
calulation until next uid proc stat change or dumpsys.

Bug: 37754877
Change-Id: I970f010a4c841c5ca26d0efc7e027414c3c952e0
Signed-off-by: Jin Qian <jinqian@google.com>
5 years agoANDROID: uid_sys_stats: fix access of task_uid(task)
Ganesh Mahendran [Tue, 25 Apr 2017 10:07:43 +0000 (18:07 +0800)]
ANDROID: uid_sys_stats: fix access of task_uid(task)

struct task_struct *task should be proteced by tasklist_lock.

Change-Id: Iefcd13442a9b9d855a2bbcde9fd838a4132fee58
Signed-off-by: Ganesh Mahendran <opensource.ganesh@gmail.com>
(cherry picked from commit 90d78776c4a0e13fb7ee5bd0787f04a1730631a6)

5 years agoANDROID: uid_sys_stats: reduce update_io_stats overhead
Jin Qian [Fri, 14 Apr 2017 00:07:58 +0000 (17:07 -0700)]
ANDROID: uid_sys_stats: reduce update_io_stats overhead

Replaced read_lock with rcu_read_lock to reduce time that preemption
is disabled.

Added a function to update io stats for specific uid and moved
hash table lookup, user_namespace out of loops.

Bug: 37319300
Change-Id: I2b81b5cd3b6399b40d08c3c14b42cad044556970
Signed-off-by: Jin Qian <jinqian@google.com>
5 years agoANDROID: uid_sys_stats: change to use rt_mutex
Wei Wang [Mon, 13 Mar 2017 19:22:21 +0000 (12:22 -0700)]
ANDROID: uid_sys_stats: change to use rt_mutex

We see this happens multiple times in heavy workload in systrace
and AMS stuck in uid_lock.

Running process:        Process 953
Running thread: android.ui
State:  Uninterruptible Sleep
Start:
1,025.628 ms
Duration:
27,955.949 ms
On CPU:
Running instead:        system_server
Args:
{kernel callsite when blocked:: "uid_procstat_write+0xb8/0x144"}

Changing to rt_mutex can mitigate the priority inversion

Bug: 34991231
Bug: 34193533
Test: on marlin
Change-Id: I28eb3971331cea60b1075740c792ab87d103262c
Signed-off-by: Wei Wang <wvw@google.com>
5 years agoANDROID: uid_sys_stats: account for fsync syscalls
Jin Qian [Thu, 2 Mar 2017 21:39:43 +0000 (13:39 -0800)]
ANDROID: uid_sys_stats: account for fsync syscalls

Change-Id: Ie888d8a0f4ec7a27dea86dc4afba8e6fd4203488
Signed-off-by: Jin Qian <jinqian@google.com>
5 years agoANDROID: uid_sys_stats: fix negative write bytes.
Jin Qian [Tue, 28 Feb 2017 23:09:42 +0000 (15:09 -0800)]
ANDROID: uid_sys_stats: fix negative write bytes.

A task can cancel writes made by other tasks. In rare cases,
cancelled_write_bytes is larger than write_bytes if the task
itself didn't make any write. This doesn't affect total size
but may cause confusion when looking at IO usage on individual
tasks.

Bug: 35851986
Change-Id: If6cb549aeef9e248e18d804293401bb2b91918ca
Signed-off-by: Jin Qian <jinqian@google.com>
5 years agoANDROID: uid_sys_stats: allow writing same state
Jin Qian [Wed, 18 Jan 2017 01:26:07 +0000 (17:26 -0800)]
ANDROID: uid_sys_stats: allow writing same state

Signed-off-by: Jin Qian <jinqian@google.com>
Bug: 34360629
Change-Id: Ia748351e07910b1febe54f0484ca1be58c4eb9c7

5 years agoANDROID: uid_sys_stats: rename uid_cputime.c to uid_sys_stats.c
Jin Qian [Wed, 11 Jan 2017 00:11:07 +0000 (16:11 -0800)]
ANDROID: uid_sys_stats: rename uid_cputime.c to uid_sys_stats.c

This module tracks cputime and io stats.

Signed-off-by: Jin Qian <jinqian@google.com>
Bug: 34198239
Change-Id: I9ee7d9e915431e0bb714b36b5a2282e1fdcc7342

5 years agoANDROID: uid_cputime: add per-uid IO usage accounting
Jin Qian [Wed, 11 Jan 2017 00:10:35 +0000 (16:10 -0800)]
ANDROID: uid_cputime: add per-uid IO usage accounting

IO usages are accounted in foreground and background buckets.
For each uid, io usage is calculated in two steps.

delta = current total of all uid tasks - previus total
current bucket += delta

Bucket is determined by current uid stat. Userspace writes to
/proc/uid_procstat/set <uid> <stat> when uid stat is updated.

/proc/uid_io/stats shows IO usage in this format.
<uid> <foreground IO> <background IO>

Signed-off-by: Jin Qian <jinqian@google.com>
Bug: 34198239
Change-Id: Ib8bebda53e7a56f45ea3eb0ec9a3153d44188102

5 years agoANDROID: uid_cputime: Check for the range while removing range of UIDs.
Ruchi Kandoi [Sat, 24 Oct 2015 00:49:11 +0000 (17:49 -0700)]
ANDROID: uid_cputime: Check for the range while removing range of UIDs.

Checking if the uid_entry->uid matches the uid intended to be removed will
prevent deleting unwanted uid_entry.
Type cast the key for the hashtable to the same size, as when they were
inserted. This will make sure that we can find the uid_entry we want.

Bug: 25195548
Change-Id: I567942123cfb20e4b61ad624da19ec4cc84642c1
Signed-off: Ruchi kandoi <kandoiruchi@google.com>

5 years agoANDROID: uid_cputime: Iterates over all the threads instead of processes.
Ruchi Kandoi [Fri, 31 Jul 2015 17:17:54 +0000 (10:17 -0700)]
ANDROID: uid_cputime: Iterates over all the threads instead of processes.

Bug: 22833116
Change-Id: I775a18f61bd2f4df2bec23d01bd49421d0969f87
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
5 years agoANDROID: uid_cputime: fix cputime overflow
Jin Qian [Tue, 14 Jul 2015 01:16:55 +0000 (18:16 -0700)]
ANDROID: uid_cputime: fix cputime overflow

Converting cputime_t to usec caused overflow when the value is greater
than 1 hour. Use msec and convert to unsigned long long to support bigger
range.

Bug: 22461683

Change-Id: I853fe3e8e7dbf0d3e2cc5c6f9688a5a6e1f1fb3e
Signed-off-by: Jin Qian <jinqian@google.com>
[AmitP: Refactored the original changes because cputime_to_jiffies()
        is obsolete and removed in upstream commit
        f22d6df0b23e ("sched/cputime: Remove jiffies based cputime")]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoANDROID: uid_cputime: Adds accounting for the cputimes per uid.
jinqian [Wed, 11 Mar 2015 17:44:50 +0000 (10:44 -0700)]
ANDROID: uid_cputime: Adds accounting for the cputimes per uid.

Adds proc files /proc/uid_cputime/show_uid_stat and
/proc/uid_cputime/remove_uid_range.

show_uid_stat lists the total utime and stime for the active as well as
terminated processes for each of the uids.

Writing a range of uids to remove_uid_range will delete the accounting
for all the uids within that range.

Change-Id: I21d9210379da730b33ddc1a0ea663c8c9d2ac15b

[AmitP: Refactored the original patch because upstream commit
        605dc2b31a2a ("tsacct: Convert obsolete cputime type to nsecs")
        made cputime_t type obsolete, so use u64 nanoseconds directly instead.

        Also folded following android-4.9 changes into this patch
        48a9906c0fd8 ("ANDROID: proc: uid_cputime: create uids from kuids")
        453ac31cab34 ("ANDROID: proc: uid_cputime: fix show_uid_stat permission")]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
5 years agoCHROMIUM: usb: gadget: f_accessory: add .raw_request callback
Mark Kuo [Mon, 11 Jan 2016 11:07:12 +0000 (19:07 +0800)]
CHROMIUM: usb: gadget: f_accessory: add .raw_request callback

After this upstream commit: 3c86726cfe38952f0366f86acfbbb025813ec1c2,
.raw_request is mandatory in hid_ll_driver structure, hence add an empty
raw_request() function.

BUG=chrome-os-partner:49140
TEST=none

Change-Id: Idd0bbe6960aad2c557376e4a24827d7e1df8e023
Signed-off-by: Mark Kuo <mkuo@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/321038
Commit-Ready: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
5 years agoCHROMIUM: usb: gadget: f_audio_source: add .free_func callback
Mark Kuo [Mon, 11 Jan 2016 09:49:16 +0000 (17:49 +0800)]
CHROMIUM: usb: gadget: f_audio_source: add .free_func callback

When userspace unbinds gadget functions through configfs, the
.free_func() callback is always invoked. (in config_usb_cfg_unlink())
Implement it as a no-op to avoid the following crash:

[ 68.125679] configfs-gadget gadget: unbind function 'accessory'/ffffffc0720bf000
[ 68.133202] configfs-gadget gadget: unbind function 'audio_source'/ffffffc0012ca3c0
[ 68.142668] tegra-xudc 700d0000.usb-device: ep 0 disabled
[ 68.148186] Bad mode in Synchronous Abort handler detected, code 0x86000006
[ 68.155144] CPU: 2 PID: 1 Comm: init Tainted: G    U W 3.18.0-09419-g87296c3-dirty #561
[ 68.163743] Hardware name: Google Tegra210 Smaug Rev 1,3+ (DT)
[ 68.169566] task: ffffffc0bc8d0000 ti: ffffffc0bc8bc000 task.ti: ffffffc0bc8bc000
[ 68.177039] PC is at 0x0
[ 68.179577] LR is at usb_put_function+0x14/0x1c
....

BUG=chrome-os-partner:49140
TEST="setprop sys.usb.config accessory,audio_source" on A44 and then
switch back to default: "setprop sys.usb.config mtp,adb", no crash will
be seen.

Change-Id: I5b6141964aab861e86e3afb139ded02d4d122dab
Signed-off-by: Mark Kuo <mkuo@nvidia.com>
Reviewed-on: https://chromium-review.googlesource.com/321013
Commit-Ready: Andrew Bresticker <abrestic@chromium.org>
Tested-by: Andrew Bresticker <abrestic@chromium.org>
Reviewed-by: Andrew Bresticker <abrestic@chromium.org>
5 years agoANDROID: usb: gadget: f_midi: set fi->f to NULL when free f_midi function
Winter Wang [Fri, 20 May 2016 03:05:00 +0000 (11:05 +0800)]
ANDROID: usb: gadget: f_midi: set fi->f to NULL when free f_midi function

fi->f is set in f_midi's alloc_func, need to clean this to
NULL in free_func, otherwise on ConfigFS's function switch,
midi->usb_function it self is freed, fi->f will be a wild
pointer and run into below kernel panic:
---------------
[   58.950628] Unable to handle kernel paging request at virtual address 63697664
[   58.957869] pgd = c0004000
[   58.960583] [63697664] *pgd=00000000
[   58.964185] Internal error: Oops: 80000005 [#1] PREEMPT SMP ARM
[   58.970111] Modules linked in:
[   58.973191] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.1.15-03504-g34c857c-dirty #89
[   58.981024] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[   58.987557] task: c110bd70 ti: c1100000 task.ti: c1100000
[   58.992962] PC is at 0x63697664
[   58.996120] LR is at android_setup+0x78/0x138
<..snip..>
[   60.044980] 1fc0: ffffffff ffffffff c1000684 00000000 00000000 c108ecd0 c11f7294 c11039c0
[   60.053181] 1fe0: c108eccc c110d148 1000406a 412fc09a 00000000 1000807c 00000000 00000000
[   60.061420] [<c073b1fc>] (android_setup) from [<c0730490>] (udc_irq+0x758/0x1034)
[   60.068951] [<c0730490>] (udc_irq) from [<c017c650>] (handle_irq_event_percpu+0x50/0x254)
[   60.077165] [<c017c650>] (handle_irq_event_percpu) from [<c017c890>] (handle_irq_event+0x3c/0x5c)
[   60.086072] [<c017c890>] (handle_irq_event) from [<c017f3ec>] (handle_fasteoi_irq+0xe0/0x198)
[   60.094630] [<c017f3ec>] (handle_fasteoi_irq) from [<c017bcfc>] (generic_handle_irq+0x2c/0x3c)
[   60.103271] [<c017bcfc>] (generic_handle_irq) from [<c017bfb8>] (__handle_domain_irq+0x7c/0xec)
[   60.112000] [<c017bfb8>] (__handle_domain_irq) from [<c0101450>] (gic_handle_irq+0x24/0x5c)
--------------

Signed-off-by: Winter Wang <wente.wang@nxp.com>
5 years agoANDROID: usb: gadget: f_midi: create F_midi device
Badhri Jagan Sridharan [Thu, 3 Sep 2015 05:49:10 +0000 (22:49 -0700)]
ANDROID: usb: gadget: f_midi: create F_midi device

Android frameworks relies on the alsa
config reported by the f_midi device.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: I0695e00b166fd953f50acea93802245b0d5a5240

5 years agoANDROID: usb: gadget: f_accessory: assign no-op request complete callbacks
Badhri Jagan Sridharan [Fri, 21 Jul 2017 21:58:16 +0000 (14:58 -0700)]
ANDROID: usb: gadget: f_accessory: assign no-op request complete callbacks

The req->complete seems to presist the callback pointer for
the control requests. This causes the serial of the accessory
to be overridden when an accessory function specific out
control request is issued right after the  ACCESSORY_SEND_STRING
control request. Therefore, assign a no-op req complete function
when nothing needs to be done once the request is completed.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Bug: 63867169
Change-Id: I78c1602e9a044b8718b270b8a068cf5afc83f984