firefly-linux-kernel-4.4.55.git
10 years agocpufreq: Add EXPORT_SYMBOL_GPL for have_governor_per_policy
Viresh Kumar [Thu, 16 May 2013 05:09:56 +0000 (05:09 +0000)]
cpufreq: Add EXPORT_SYMBOL_GPL for have_governor_per_policy

This patch adds: EXPORT_SYMBOL_GPL(have_governor_per_policy), so that
this routine can be used by modules too.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
10 years agotcp: add a sysctl to config the tcp_default_init_rwnd
JP Abgrall [Sat, 8 Feb 2014 02:40:10 +0000 (18:40 -0800)]
tcp: add a sysctl to config the tcp_default_init_rwnd

The default initial rwnd is hardcoded to 10.

Now we allow it to be controlled via
  /proc/sys/net/ipv4/tcp_default_init_rwnd
which limits the values from 3 to 100

This is somewhat needed because ipv6 routes are
autoconfigured by the kernel.

See "An Argument for Increasing TCP's Initial Congestion Window"
in https://developers.google.com/speed/articles/tcp_initcwnd_paper.pdf

Change-Id: I386b2a9d62de0ebe05c1ebe1b4bd91b314af5c54
Signed-off-by: JP Abgrall <jpa@google.com>
Conflicts:
net/ipv4/sysctl_net_ipv4.c
net/ipv4/tcp_input.c

10 years agoSELinux: Fix kernel BUG on empty security contexts.
Stephen Smalley [Thu, 30 Jan 2014 16:26:59 +0000 (11:26 -0500)]
SELinux: Fix kernel BUG on empty security contexts.

Setting an empty security context (length=0) on a file will
lead to incorrectly dereferencing the type and other fields
of the security context structure, yielding a kernel BUG.
As a zero-length security context is never valid, just reject
all such security contexts whether coming from userspace
via setxattr or coming from the filesystem upon a getxattr
request by SELinux.

Setting a security context value (empty or otherwise) unknown to
SELinux in the first place is only possible for a root process
(CAP_MAC_ADMIN), and, if running SELinux in enforcing mode, only
if the corresponding SELinux mac_admin permission is also granted
to the domain by policy.  In Fedora policies, this is only allowed for
specific domains such as livecd for setting down security contexts
that are not defined in the build host policy.

[On Android, this can only be set by root/CAP_MAC_ADMIN processes,
and if running SELinux in enforcing mode, only if mac_admin permission
is granted in policy.  In Android 4.4, this would only be allowed for
root/CAP_MAC_ADMIN processes that are also in unconfined domains. In current
AOSP master, mac_admin is not allowed for any domains except the recovery
console which has a legitimate need for it.  The other potential vector
is mounting a maliciously crafted filesystem for which SELinux fetches
xattrs (e.g. an ext4 filesystem on a SDcard).  However, the end result is
only a local denial-of-service (DOS) due to kernel BUG.  This fix is
queued for 3.14.]

Reproducer:
su
setenforce 0
touch foo
setfattr -n security.selinux foo

Caveat:
Relabeling or removing foo after doing the above may not be possible
without booting with SELinux disabled.  Any subsequent access to foo
after doing the above will also trigger the BUG.

BUG output from Matthew Thode:
[  473.893141] ------------[ cut here ]------------
[  473.962110] kernel BUG at security/selinux/ss/services.c:654!
[  473.995314] invalid opcode: 0000 [#6] SMP
[  474.027196] Modules linked in:
[  474.058118] CPU: 0 PID: 8138 Comm: ls Tainted: G      D   I
3.13.0-grsec #1
[  474.116637] Hardware name: Supermicro X8ST3/X8ST3, BIOS 2.0
07/29/10
[  474.149768] task: ffff8805f50cd010 ti: ffff8805f50cd488 task.ti:
ffff8805f50cd488
[  474.183707] RIP: 0010:[<ffffffff814681c7>]  [<ffffffff814681c7>]
context_struct_compute_av+0xce/0x308
[  474.219954] RSP: 0018:ffff8805c0ac3c38  EFLAGS: 00010246
[  474.252253] RAX: 0000000000000000 RBX: ffff8805c0ac3d94 RCX:
0000000000000100
[  474.287018] RDX: ffff8805e8aac000 RSI: 00000000ffffffff RDI:
ffff8805e8aaa000
[  474.321199] RBP: ffff8805c0ac3cb8 R08: 0000000000000010 R09:
0000000000000006
[  474.357446] R10: 0000000000000000 R11: ffff8805c567a000 R12:
0000000000000006
[  474.419191] R13: ffff8805c2b74e88 R14: 00000000000001da R15:
0000000000000000
[  474.453816] FS:  00007f2e75220800(0000) GS:ffff88061fc00000(0000)
knlGS:0000000000000000
[  474.489254] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  474.522215] CR2: 00007f2e74716090 CR3: 00000005c085e000 CR4:
00000000000207f0
[  474.556058] Stack:
[  474.584325]  ffff8805c0ac3c98 ffffffff811b549b ffff8805c0ac3c98
ffff8805f1190a40
[  474.618913]  ffff8805a6202f08 ffff8805c2b74e88 00068800d0464990
ffff8805e8aac860
[  474.653955]  ffff8805c0ac3cb8 000700068113833a ffff880606c75060
ffff8805c0ac3d94
[  474.690461] Call Trace:
[  474.723779]  [<ffffffff811b549b>] ? lookup_fast+0x1cd/0x22a
[  474.778049]  [<ffffffff81468824>] security_compute_av+0xf4/0x20b
[  474.811398]  [<ffffffff8196f419>] avc_compute_av+0x2a/0x179
[  474.843813]  [<ffffffff8145727b>] avc_has_perm+0x45/0xf4
[  474.875694]  [<ffffffff81457d0e>] inode_has_perm+0x2a/0x31
[  474.907370]  [<ffffffff81457e76>] selinux_inode_getattr+0x3c/0x3e
[  474.938726]  [<ffffffff81455cf6>] security_inode_getattr+0x1b/0x22
[  474.970036]  [<ffffffff811b057d>] vfs_getattr+0x19/0x2d
[  475.000618]  [<ffffffff811b05e5>] vfs_fstatat+0x54/0x91
[  475.030402]  [<ffffffff811b063b>] vfs_lstat+0x19/0x1b
[  475.061097]  [<ffffffff811b077e>] SyS_newlstat+0x15/0x30
[  475.094595]  [<ffffffff8113c5c1>] ? __audit_syscall_entry+0xa1/0xc3
[  475.148405]  [<ffffffff8197791e>] system_call_fastpath+0x16/0x1b
[  475.179201] Code: 00 48 85 c0 48 89 45 b8 75 02 0f 0b 48 8b 45 a0 48
8b 3d 45 d0 b6 00 8b 40 08 89 c6 ff ce e8 d1 b0 06 00 48 85 c0 49 89 c7
75 02 <0f> 0b 48 8b 45 b8 4c 8b 28 eb 1e 49 8d 7d 08 be 80 01 00 00 e8
[  475.255884] RIP  [<ffffffff814681c7>]
context_struct_compute_av+0xce/0x308
[  475.296120]  RSP <ffff8805c0ac3c38>
[  475.328734] ---[ end trace f076482e9d754adc ]---

[sds:  commit message edited to note Android implications and
to generate a unique Change-Id for gerrit]

Change-Id: I4d5389f0cfa72b5f59dada45081fa47e03805413
Reported-by: Matthew Thode <mthode@mthode.org>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Cc: stable@vger.kernel.org
Signed-off-by: Paul Moore <pmoore@redhat.com>
10 years agoARM: tegra: flounder: stick to 32bit binder for now.
JP Abgrall [Wed, 5 Feb 2014 20:29:34 +0000 (12:29 -0800)]
ARM: tegra: flounder: stick to 32bit binder for now.

Signed-off-by: JP Abgrall <jpa@google.com>
10 years agonetfilter: xt_IDLETIMER: Revert to retain the kernel API format.
Ashish Sharma [Wed, 5 Feb 2014 01:50:50 +0000 (01:50 +0000)]
netfilter: xt_IDLETIMER: Revert to retain the kernel API format.

Reverted Change-Id: Iaeca5dd2d7878c0733923ae03309a2a7b86979ca

Change-Id: I0e0a4f60ec14330d8d8d1c5a508fa058d9919e07
Signed-off-by: Ashish Sharma <ashishsharma@google.com>
(cherry picked from commit e0a4e5b0e808d718dd9af500c5754118fc3935db)

10 years agoSELinux: Fix possible NULL pointer dereference in selinux_inode_permission()
Steven Rostedt [Fri, 10 Jan 2014 02:46:34 +0000 (21:46 -0500)]
SELinux: Fix possible NULL pointer dereference in selinux_inode_permission()

commit 3dc91d4338d698ce77832985f9cb183d8eeaf6be upstream.

While running stress tests on adding and deleting ftrace instances I hit
this bug:

  BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
  IP: selinux_inode_permission+0x85/0x160
  PGD 63681067 PUD 7ddbe067 PMD 0
  Oops: 0000 [#1] PREEMPT
  CPU: 0 PID: 5634 Comm: ftrace-test-mki Not tainted 3.13.0-rc4-test-00033-gd2a6dde-dirty #20
  Hardware name:                  /DG965MQ, BIOS MQ96510J.86A.0372.2006.0605.1717 06/05/2006
  task: ffff880078375800 ti: ffff88007ddb0000 task.ti: ffff88007ddb0000
  RIP: 0010:[<ffffffff812d8bc5>]  [<ffffffff812d8bc5>] selinux_inode_permission+0x85/0x160
  RSP: 0018:ffff88007ddb1c48  EFLAGS: 00010246
  RAX: 0000000000000000 RBX: 0000000000800000 RCX: ffff88006dd43840
  RDX: 0000000000000001 RSI: 0000000000000081 RDI: ffff88006ee46000
  RBP: ffff88007ddb1c88 R08: 0000000000000000 R09: ffff88007ddb1c54
  R10: 6e6576652f6f6f66 R11: 0000000000000003 R12: 0000000000000000
  R13: 0000000000000081 R14: ffff88006ee46000 R15: 0000000000000000
  FS:  00007f217b5b6700(0000) GS:ffffffff81e21000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033^M
  CR2: 0000000000000020 CR3: 000000006a0fe000 CR4: 00000000000007f0
  Call Trace:
    security_inode_permission+0x1c/0x30
    __inode_permission+0x41/0xa0
    inode_permission+0x18/0x50
    link_path_walk+0x66/0x920
    path_openat+0xa6/0x6c0
    do_filp_open+0x43/0xa0
    do_sys_open+0x146/0x240
    SyS_open+0x1e/0x20
    system_call_fastpath+0x16/0x1b
  Code: 84 a1 00 00 00 81 e3 00 20 00 00 89 d8 83 c8 02 40 f6 c6 04 0f 45 d8 40 f6 c6 08 74 71 80 cf 02 49 8b 46 38 4c 8d 4d cc 45 31 c0 <0f> b7 50 20 8b 70 1c 48 8b 41 70 89 d9 8b 78 04 e8 36 cf ff ff
  RIP  selinux_inode_permission+0x85/0x160
  CR2: 0000000000000020

Investigating, I found that the inode->i_security was NULL, and the
dereference of it caused the oops.

in selinux_inode_permission():

isec = inode->i_security;

rc = avc_has_perm_noaudit(sid, isec->sid, isec->sclass, perms, 0, &avd);

Note, the crash came from stressing the deletion and reading of debugfs
files.  I was not able to recreate this via normal files.  But I'm not
sure they are safe.  It may just be that the race window is much harder
to hit.

What seems to have happened (and what I have traced), is the file is
being opened at the same time the file or directory is being deleted.
As the dentry and inode locks are not held during the path walk, nor is
the inodes ref counts being incremented, there is nothing saving these
structures from being discarded except for an rcu_read_lock().

The rcu_read_lock() protects against freeing of the inode, but it does
not protect freeing of the inode_security_struct.  Now if the freeing of
the i_security happens with a call_rcu(), and the i_security field of
the inode is not changed (it gets freed as the inode gets freed) then
there will be no issue here.  (Linus Torvalds suggested not setting the
field to NULL such that we do not need to check if it is NULL in the
permission check).

Note, this is a hack, but it fixes the problem at hand.  A real fix is
to restructure the destroy_inode() to call all the destructor handlers
from the RCU callback.  But that is a major job to do, and requires a
lot of work.  For now, we just band-aid this bug with this fix (it
works), and work on a more maintainable solution in the future.

Link: http://lkml.kernel.org/r/20140109101932.0508dec7@gandalf.local.home
Link: http://lkml.kernel.org/r/20140109182756.17abaaa8@gandalf.local.home
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agoStaging: android: binder: Support concurrent 32 bit and 64 bit processes.
Arve Hjønnevåg [Tue, 28 Jan 2014 03:18:47 +0000 (19:18 -0800)]
Staging: android: binder: Support concurrent 32 bit and 64 bit processes.

Add binder_size_t and binder_uintptr_t that is used instead of size_t and
void __user * in the user-space interface.

Use 64 bit pointers on all systems unless CONFIG_ANDROID_BINDER_IPC_32BIT
is set (which enables the old protocol on 32 bit systems).

Change BINDER_CURRENT_PROTOCOL_VERSION to 8 if
CONFIG_ANDROID_BINDER_IPC_32BIT is not set.

Add compat ioctl.

Change-Id: Ifbbde0209da0050011bcab34c547a4c30d6e8c49
Signed-off-by: Arve Hjønnevåg <arve@android.com>
10 years agostaging: android: binder: fix ABI for 64bit Android
Serban Constantinescu [Wed, 15 Jan 2014 11:28:36 +0000 (11:28 +0000)]
staging: android: binder: fix ABI for 64bit Android

This patch fixes the ABI for 64bit Android userspace.
BC_REQUEST_DEATH_NOTIFICATION and BC_CLEAR_DEATH_NOTIFICATION claim
to be using struct binder_ptr_cookie, but they are using a 32bit handle
and a pointer.

On 32bit systems the payload size is the same as the size of struct
binder_ptr_cookie, however for 64bit systems this will differ. This
patch adds struct binder_handle_cookie that fixes this issue for 64bit
Android.

Since there are no 64bit users of this interface that we know of this
change should not affect any existing systems.

Change-Id: I8909cbc50aad48ccf371270bad6f69ff242a8c22
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
10 years agostaging: android: binder: fix binder interface for 64bit compat layer
Serban Constantinescu [Thu, 4 Jul 2013 09:54:48 +0000 (10:54 +0100)]
staging: android: binder: fix binder interface for 64bit compat layer

The changes in this patch will fix the binder interface for use on 64bit
machines and stand as the base of the 64bit compat support. The changes
apply to the structures that are passed between the kernel and
userspace.

Most of the  changes applied mirror the change to struct binder_version
where there is no need for a 64bit wide protocol_version(on 64bit
machines). The change inlines with the existing 32bit userspace(the
structure has the same size) and simplifies the compat layer such that
the same handler can service the BINDER_VERSION ioctl.

Other changes make use of kernel types as well as user-exportable ones
and fix format specifier issues.

The changes do not affect existing 32bit ABI.

Change-Id: Icccc8d47c302930cc61cddc5749b4cc74dc84117
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: android: binder: replace types with portable ones
Serban Constantinescu [Thu, 4 Jul 2013 09:54:47 +0000 (10:54 +0100)]
staging: android: binder: replace types with portable ones

Since this driver is meant to be used on different types of processors
and a portable driver should specify the size a variable expects to be
this patch changes the types used throughout the binder interface.

We use "userspace" types since this header will be exported and used by
the Android filesystem.

The patch does not change in any way the functionality of the binder driver.

Change-Id: Ib26daab8bc44b92d4a09badc8ecb64d37ee8773b
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: android: binder: fix alignment issues
Serban Constantinescu [Thu, 4 Jul 2013 09:54:46 +0000 (10:54 +0100)]
staging: android: binder: fix alignment issues

The Android userspace aligns the data written to the binder buffers to
4bytes. Thus for 32bit platforms or 64bit platforms running an 32bit
Android userspace we can have a buffer looking like this:

platform    buffer(binder_cmd   pointer)      size
32/32                 32b         32b          8B
64/32                 32b         64b          12B
64/64                 32b         64b          12B

Thus the kernel needs to check that the buffer size is aligned to 4bytes
not to (void *) that will be 8bytes on 64bit machines.

The change does not affect existing 32bit ABI.

Change-Id: I7535f07301519623ea6334f525d312d687407ed4
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: android: binder: fix BC_FREE_BUFFER ioctl declaration
Serban Constantinescu [Thu, 4 Jul 2013 09:54:45 +0000 (10:54 +0100)]
staging: android: binder: fix BC_FREE_BUFFER ioctl declaration

BinderDriverCommands mirror the ioctl usage. Thus the size of the
structure passed through the interface should be used to generate the
ioctl No.

The change reflects the type being passed from the user space-a pointer
to a binder_buffer. This change should not affect the existing 32bit
user space since BC_FREE_BUFFER is computed as:

   #define _IOW(type,nr,size)         \
      ((type) << _IOC_TYPESHIFT) |    \
      ((nr)   << _IOC_NRSHIFT) |      \
      ((size) << _IOC_SIZESHIFT))

and for a 32bit compiler BC_FREE_BUFFER will have the same computed
value. This change will also ease our work in differentiating
BC_FREE_BUFFER from COMPAT_BC_FREE_BUFFER.

The change does not affect existing 32bit ABI.

Change-Id: I2e0ae87bc4e913225a8eb2912913f7e3617cb575
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: android: binder: fix BINDER_SET_MAX_THREADS declaration
Serban Constantinescu [Thu, 4 Jul 2013 09:54:44 +0000 (10:54 +0100)]
staging: android: binder: fix BINDER_SET_MAX_THREADS declaration

This change will fix the BINDER_SET_MAX_THREADS ioctl to use __u32
instead of size_t for setting the max threads. Thus using the same
handler for 32 and 64bit kernels.

This value is stored internally in struct binder_proc and set to 15
on open_binder() in the libbinder API(thus no need for a 64bit size_t
on 64bit platforms).

The change does not affect existing 32bit ABI.

Change-Id: Ibdfe10a70d475a91c247dc36e9cfd74a259d50e4
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: android: binder: modify struct binder_write_read to use size_t
Serban Constantinescu [Thu, 4 Jul 2013 09:54:43 +0000 (10:54 +0100)]
staging: android: binder: modify struct binder_write_read to use size_t

This change mirrors the userspace operation where struct binder_write_read
members that specify the buffer size and consumed size are size_t elements.

The patch also fixes the binder_thread_write() and binder_thread_read()
functions prototypes to conform with the definition of binder_write_read.

The changes do not affect existing 32bit ABI.

Change-Id: I987246d507b9c5e4627c62a1da971d11869ac5a0
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
Acked-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agoFix aarch64 build issue with ION
John Stultz [Fri, 31 Jan 2014 19:22:18 +0000 (11:22 -0800)]
Fix aarch64 build issue with ION

In trying to build ION for aarch64, I came across the following build error:

In file included from /home/jstultz/projects/linux/linaro.android/arch/arm64/include/asm/page.h:39:0,
                 from drivers/staging/android/ion/ion_system_heap.c:17:
/home/jstultz/projects/linux/linaro.android/arch/arm64/include/asm/pgtable-3level-types.h:19:1: error: unknown type name u64
 typedef u64 pteval_t;
 ^
/home/jstultz/projects/linux/linaro.android/arch/arm64/include/asm/pgtable-3level-types.h:20:1: error: unknown type name u64
 typedef u64 pmdval_t;
 ^
...

The problem is asm/page.h doesn't include anything that defines u64, so
add an asm/types.h include to the pgtable-3level-types.h to match upstream
and avoid the issue.

Change-Id: I3f098bf666761ac6b316389a46d37cc449c342d6
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agoping: prevent NULL pointer dereference on write to msg_name
Hannes Frederic Sowa [Mon, 18 Nov 2013 06:07:45 +0000 (07:07 +0100)]
ping: prevent NULL pointer dereference on write to msg_name

A plain read() on a socket does set msg->msg_name to NULL. So check for
NULL pointer first.

[Backport of net-next cf970c002d270c36202bd5b9c2804d3097a52da0]

Bug: 12780426
Change-Id: I3df76aca2fa56478b9a33c404f7b1f0940475ef7
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
10 years agonet: ipv6: add missing lock in ping_v6_sendmsg
Lorenzo Colitti [Wed, 3 Jul 2013 15:52:49 +0000 (00:52 +0900)]
net: ipv6: add missing lock in ping_v6_sendmsg

[net-next commit a1bdc45580fc19e968b32ad27cd7e476a4aa58f6]

Bug: 12800827
Change-Id: I93d897e5043dc89bc99f111c89ef4f8b1fa1885d
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
10 years agonet: ipv6: fix wrong ping_v6_sendmsg return value
Lorenzo Colitti [Wed, 3 Jul 2013 15:12:40 +0000 (00:12 +0900)]
net: ipv6: fix wrong ping_v6_sendmsg return value

[net-next commit fbfe80c890a1dc521d0b629b870e32fcffff0da5]

ping_v6_sendmsg currently returns 0 on success. It should return
the number of bytes written instead.

Bug: 12800827
Change-Id: I7ed17dc61afbb68a84908e67e44db976ec812bad
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
10 years agoping: always initialize ->sin6_scope_id and ->sin6_flowinfo
Cong Wang [Sun, 2 Jun 2013 22:43:52 +0000 (22:43 +0000)]
ping: always initialize ->sin6_scope_id and ->sin6_flowinfo

[net-next commit c26d6b46da3ee86fa8a864347331e5513ca84c2b]

If we don't need scope id, we should initialize it to zero.
Same for ->sin6_flowinfo.

Bug: 12800827
Change-Id: Ic19792cee3f5dc30237562cf48e6bdf49817c96e
Cc: Lorenzo Colitti <lorenzo@google.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
Acked-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
10 years agonet: ipv6: Add IPv6 support to the ping socket.
Lorenzo Colitti [Wed, 22 May 2013 20:17:31 +0000 (20:17 +0000)]
net: ipv6: Add IPv6 support to the ping socket.

[net-next commit 6d0bfe22611602f36617bc7aa2ffa1bbb2f54c67]

This adds the ability to send ICMPv6 echo requests without a
raw socket. The equivalent ability for ICMPv4 was added in
2011.

Instead of having separate code paths for IPv4 and IPv6, make
most of the code in net/ipv4/ping.c dual-stack and only add a
few IPv6-specific bits (like the protocol definition) to a new
net/ipv6/ping.c. Hopefully this will reduce divergence and/or
duplication of bugs in the future.

Caveats:

- Setting options via ancillary data (e.g., using IPV6_PKTINFO
  to specify the outgoing interface) is not yet supported.
- There are no separate security settings for IPv4 and IPv6;
  everything is controlled by /proc/net/ipv4/ping_group_range.
- The proc interface does not yet display IPv6 ping sockets
  properly.

Tested with a patched copy of ping6 and using raw socket calls.
Compiles and works with all of CONFIG_IPV6={n,m,y}.

Bug: 12800827
Change-Id: I718cd9931823873ab44df22e8a66e12d6a0a6eb1
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
10 years agostaging: ion: Build fix for compat_ion.c
John Stultz [Wed, 29 Jan 2014 21:00:51 +0000 (13:00 -0800)]
staging: ion: Build fix for compat_ion.c

compat_get_ion_handle_data is missing a declaration for
the return value.

This patch simply adds it, so things build.

Change-Id: I1a72a3c56975dc614322a63852f2a6554f2be107
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agoion: Fix ION_IOC_FREE compat ioctl
Laura Abbott [Tue, 28 Jan 2014 23:39:48 +0000 (15:39 -0800)]
ion: Fix ION_IOC_FREE compat ioctl

The compat ioctl for ION_IOC_FREE currently passes allocation data
instead of the free data. Correct this.

Change-Id: I5108a1937104b8368426f7695b4a2df416036a87
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
10 years agoandroid: configs: update 3.10 options
Rom Lemarchand [Tue, 28 Jan 2014 18:23:19 +0000 (10:23 -0800)]
android: configs: update 3.10 options

Change-Id: Ifbda55e570a22ace98d7d74b057ba21a597e0826

10 years agoandroid: configs: Add CONFIG_NETFILTER_XT_TARGET_IDLETIMER
Ashish Sharma [Thu, 16 Jan 2014 00:47:16 +0000 (16:47 -0800)]
android: configs: Add CONFIG_NETFILTER_XT_TARGET_IDLETIMER

Signed-off-by: Ashish Sharma <ashishsharma@google.com>
(cherry picked from commit 5621df1091c7e103bca6cdd1dbecf4333efad4e7)

Change-Id: I3104266fa648fc024fee45f1ce9800142898baf7

10 years agocpufreq: interactive: fix NULL pointer dereference at sysfs ops
Minsung Kim [Sun, 19 Jan 2014 05:32:42 +0000 (14:32 +0900)]
cpufreq: interactive: fix NULL pointer dereference at sysfs ops

sysfs ops for target_loads and above_hispeed_delay can be called before
initializing tunables at CPUFREQ_GOV_POLICY_INIT. Create sysfs entries after
initialization.

Change-Id: I50356198d7629731c0d32a3066d61fe8354e0001
Signed-off-by: Minsung Kim <ms925.kim@samsung.com>
10 years agovideo: adf: define constants for device-custom ioctls
Greg Hackmann [Mon, 13 Jan 2014 23:24:24 +0000 (15:24 -0800)]
video: adf: define constants for device-custom ioctls

Device-custom ADF ioctls can use type ADF_IOCTL_TYPE and
nr >= ADF_IOCTL_NR_CUSTOM

Change-Id: Ia8270973df5100e996ca0e021ede60e54b9af72a
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agoarm64: documentation: tighten up tagged pointer documentation
Will Deacon [Tue, 17 Sep 2013 10:46:23 +0000 (11:46 +0100)]
arm64: documentation: tighten up tagged pointer documentation

Commit d50240a5f6ce ("arm64: mm: permit use of tagged pointers at EL0")
added support for tagged pointers in userspace, but the corresponding
update to Documentation/ contained some imprecise statements.

This patch fixes up some minor ambiguities in the text, hopefully making
it more clear about exactly what the kernel expects from user virtual
addresses.

Change-Id: I7df342e01d5253ccacb3847449940892768d7e07
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
10 years agoarm64: mm: permit use of tagged pointers at EL0
Will Deacon [Wed, 12 Jun 2013 15:28:04 +0000 (16:28 +0100)]
arm64: mm: permit use of tagged pointers at EL0

TCR.TBI0 can be used to cause hardware address translation to ignore the
top byte of userspace virtual addresses. Whilst not especially useful in
standard C programs, this can be used by JITs to `tag' pointers with
various pieces of metadata.

This patch enables this bit for AArch64 Linux, and adds a new file to
Documentation/arm64/ which describes some potential caveats when using
tagged virtual addresses.

Change-Id: I4c025d026144c69a2259b6562e46176f95b4e110
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
10 years agoandroid: configs: add IPV6 ROUTE INFO
JP Abgrall [Tue, 7 Jan 2014 22:25:28 +0000 (14:25 -0800)]
android: configs: add IPV6 ROUTE INFO

Change-Id: I54cba86bce703647c4be8eee5592d55374ad02ef
Signed-off-by: JP Abgrall <jpa@google.com>
(cherry picked from commit 5e35d662616142d308ce24c9d552e469f60d8695)

10 years agocpufreq: interactive: fix compiling warnings
Chih-Wei Huang [Tue, 24 Dec 2013 09:51:55 +0000 (17:51 +0800)]
cpufreq: interactive: fix compiling warnings

The gcc warns like:

  cpufreq_interactive.c:745:6: warning: operation on 'ret' may be undefined [-Wsequence-point]

It was introduced by commit cf0fad49d17cb8273ce555dd5b7afab67d7923bf.

Since sprintf(...) just return 1 (one character) in this case, ret should not changed.
Just discarding the result of sprintf(...) leads to the result that
the committer of cf0fad49d17cb8273ce555dd5b7afab67d7923bf wants.

Change-Id: Ifed1cef6d6a31c3ed23dad03a567b3b9eddf3a57
Signed-off-by: Chih-Wei Huang <cwhuang@android-x86.org>
10 years agoandroid: configs: add TIMER_STATS back, helps with sysrq t.
JP Abgrall [Fri, 27 Dec 2013 23:20:32 +0000 (15:20 -0800)]
android: configs: add TIMER_STATS back, helps with sysrq t.

Change-Id: I8fe033090e38523152225dcfb7a1828f530a0757
Signed-off-by: JP Abgrall <jpa@google.com>
(cherry picked from commit 7aee29d6482954ac9fecae3ce8a90b6759158107)

10 years agoion: fix overflow and list bugs in system heap
Colin Cross [Fri, 20 Dec 2013 02:37:49 +0000 (18:37 -0800)]
ion: fix overflow and list bugs in system heap

Fix a few bugs in ion_system_heap:

Initialize the list node in the info block.

Don't store size_remaining in a signed long, allocating >2GB
could overflow, resulting in a call to sg_alloc_table with
nents=0 which panics.  alloc_largest_available will never
return a block larger than size_remanining, so it can never
go negative.

Limit a single allocation to half of all memory.  Prevents a
large allocation from taking down the whole system.

Change-Id: I7fcbd7e1d5b4d482d7612d80b6c9e8e24466f1d8
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: Add private buffer flag to skip page pooling on free
Mitchel Humpherys [Tue, 6 Aug 2013 22:08:23 +0000 (15:08 -0700)]
ion: Add private buffer flag to skip page pooling on free

Currently, when we free a buffer it might actually just go back into a
heap-specific page pool rather than going back to the system. This poses
a problem because sometimes (like when we're running a shrinker in low
memory conditions) we need to force the memory associated with the
buffer to truly be relinquished to the system rather than just going
back into a page pool.

There isn't a use case for this flag by Ion clients, so make it a
private flag. The main use case right now is to provide a mechanism for
the deferred free code to force stale buffers to bypass page pooling.

Change-Id: I724f89cc037083fe8576784363caa18a34e8705a
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
10 years agogpu: ion: make sure all clients are exposed in debugfs
Mitchel Humpherys [Mon, 7 Oct 2013 16:24:29 +0000 (09:24 -0700)]
gpu: ion: make sure all clients are exposed in debugfs

Currently, if multiple Ion clients are created with the same name, only
the first one shows up in debugfs. Rectify this by adding a
monotonically-increasing serial number to the debug names of Ion
clients.

Change-Id: I000e45055d5029c7bccd88c36b238736929da3a5
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
10 years agoion: store a copy of the client name on client creation
Mitchel Humpherys [Thu, 19 Dec 2013 06:10:07 +0000 (22:10 -0800)]
ion: store a copy of the client name on client creation

Currently, we copy the pointer passed in to ion_client_create without
making a copy of the string itself. This approach is problematic since
it relies on the client keeping the name string in working order.

Change-Id: I62d79c7539b2c857a5a625339d49c9c892e8622d
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
10 years agogpu: ion: Fix debugfs handling of multiple kernel clients
Laura Abbott [Mon, 5 Dec 2011 23:32:36 +0000 (15:32 -0800)]
gpu: ion: Fix debugfs handling of multiple kernel clients

Currently, Ion registers all debugfs entries for clients
via pid. If there are multiple kernel clients, this means
the debugfs entry only gets created for the first one. Fix
this by creating debugfs entries by name always. When
creating user clients, specify the name via the pid.

Change-Id: I00cbb284d1c53b3362bb7be9c0275620a9fac167
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
10 years agogpu: ion: create separate heap and client debugfs directories
Mitchel Humpherys [Thu, 29 Aug 2013 22:28:58 +0000 (15:28 -0700)]
gpu: ion: create separate heap and client debugfs directories

It can be slightly annoying to figure out which files under the ion
debugfs directory are heap debug files and which ones are client debug
files. Create separate subdirectories under ion to hold the different
types of debug files.

Change-Id: Ic773ab619ef94b9b4d0f3794def9d37645c7c212
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
10 years agoion: move shrinker out of heaps
Colin Cross [Fri, 13 Dec 2013 01:50:35 +0000 (17:50 -0800)]
ion: move shrinker out of heaps

Every heap that uses deferred frees is going to need a shrinker
to shrink the freelist under memory pressure.  Rather than
requiring each heap to implement a shrinker, automatically
register a shrinker if the deferred free flag is set.
The system heap also needs to shrink its page pools, so add
a shrink function to the heap ops that will be called after
shrinking the freelists.

Change-Id: Icda722d683426fadb8ddd1c8e9499264ab682c57
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion_test: Add compat_ioctl support (v2)
John Stultz [Thu, 19 Dec 2013 23:56:23 +0000 (15:56 -0800)]
ion_test: Add compat_ioctl support (v2)

Prior to subitting this, Colin reworked the compat_ioctl support
for the ion_test driver, moving the structure to be the same size
on both 32 and 64 bit architectures.

Two small things were left out. The compat_ioctl ptr assignment,
and the fact that despite having uniform sized types in the
structure, the structure pads out to different sizes on different
arches.

This patch resolves this issue by adding a padding entry after
the write flag, and adding the compat_ioctl ptr.

Changes in v2:
- Add a padding int rather then making write a u64

Cc: Colin Cross <ccross@android.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agostaging: ion: Avoid using rt_mutexes directly
John Stultz [Wed, 18 Dec 2013 01:04:29 +0000 (17:04 -0800)]
staging: ion: Avoid using rt_mutexes directly

RT_MUTEXES can be configured out of the kernel, causing compile
problems with ION.

To quote Colin:
"rt_mutexes were added with the deferred freeing feature.  Heaps need
to return zeroed memory to userspace, but zeroing the memory on every
allocation was causing performance issues.  We added a SCHED_IDLE
thread to zero memory in the background after freeing, but locking the
heap from the SCHED_IDLE thread might block a high priority allocation
thread for a long time.

The lock is only used to protect the heap's free_list and
free_list_size members, and is not held for any long or sleeping
operations.  Converting to a spinlock should prevent priority
inversion without using the rt_mutex.  I'd also rename it to free_lock
to so it doesn't get used as a general heap lock."

Thus this patch converts the rt_mutex usage to a spinlock and
renames the lock free_lock to be more clear as to its use.

I also had to change a bit of logic in ion_heap_freelist_drain()
to safely avoid list corruption.

Acked-by: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Reported-by: Jim Davis <jim.epost@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: ion: Fix possible null pointer dereference
John Stultz [Tue, 17 Dec 2013 05:07:52 +0000 (21:07 -0800)]
staging: ion: Fix possible null pointer dereference

The kbuild test robot reported:

drivers/staging/android/ion/ion_system_heap.c:122 alloc_largest_available() error: potential null dereference 'info'.  (kmalloc returns null)

Where the pointer returned from kmalloc goes unchecked for failure.

This patch checks the return for NULL, and reworks the logic, as
suggested by Colin, so we allocate the page_info structure first.

Acked-by: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agostaging: ion: Add HAVE_MEMBLOCK config dependency
John Stultz [Tue, 17 Dec 2013 05:07:51 +0000 (21:07 -0800)]
staging: ion: Add HAVE_MEMBLOCK config dependency

The kbuild test robot reported a build issue w/ ION on m68k:

drivers/staging/android/ion/ion.c: In function 'ion_reserve':
drivers/staging/android/ion/ion.c:1526:4: error: implicit declaration of function 'memblock_alloc_base' [-Werror=implicit-function-declaration]
drivers/staging/android/ion/ion.c:1528:11: error: 'MEMBLOCK_ALLOC_ANYWHERE' undeclared (first use in this function)
drivers/staging/android/ion/ion.c:1528:11: note: each undeclared identifier is reported only once for each function it appears in
drivers/staging/android/ion/ion.c:1537:4: error: implicit declaration of function 'memblock_reserve' [-Werror=implicit-function-declaration]
   cc1: some warnings being treated as errors

This is caused by ION using memblock functionality which m68k doesn't support.

This patch adds a HAVE_MEMBLOCK dependency to the ION config.

Acked-by: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogpu: ion: fix sparse non static symbol warnings
Wei Yongjun [Tue, 17 Dec 2013 03:20:22 +0000 (11:20 +0800)]
gpu: ion: fix sparse non static symbol warnings

Fixes the following sparse warnings:

drivers/staging/android/ion/tegra/tegra_ion.c:23:19: warning:
 symbol 'idev' was not declared. Should it be static?
drivers/staging/android/ion/tegra/tegra_ion.c:24:19: warning:
 symbol 'tegra_user_mapper' was not declared. Should it be static?
drivers/staging/android/ion/tegra/tegra_ion.c:25:5: warning:
 symbol 'num_heaps' was not declared. Should it be static?
drivers/staging/android/ion/tegra/tegra_ion.c:26:17: warning:
 symbol 'heaps' was not declared. Should it be static?
drivers/staging/android/ion/tegra/tegra_ion.c:28:5: warning:
 symbol 'tegra_ion_probe' was not declared. Should it be static?
drivers/staging/android/ion/tegra/tegra_ion.c:66:5: warning:
 symbol 'tegra_ion_remove' was not declared. Should it be static?

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogpu: ion: use module_platform_driver to simplify the code
Wei Yongjun [Tue, 17 Dec 2013 03:16:41 +0000 (11:16 +0800)]
gpu: ion: use module_platform_driver to simplify the code

module_platform_driver() makes the code simpler by eliminating
boilerplate code.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogpiolib: remove warnning of allocations with IRQs disabled
Zhangfei Gao [Sun, 9 Jun 2013 03:08:32 +0000 (11:08 +0800)]
gpiolib: remove warnning of allocations with IRQs disabled

Move of_gpiochip_add outof spin_lock, since kzalloc inside
of_gpiochip_add -> of_gpiochip_add_pin_range -> gpiochip_add_pin_range -> kzalloc

WARNING: at kernel/lockdep.c:2740 lockdep_trace_alloc+0xf8/0xfc()
DEBUG_LOCKS_WARN_ON(irqs_disabled_flags(flags))

Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
10 years agoandroid: configs: Add HIDRAW to recommended set
Michael Wright [Wed, 4 Dec 2013 23:23:41 +0000 (15:23 -0800)]
android: configs: Add HIDRAW to recommended set

The Logitech unifying driver depends on hidraw being available.
Recommending one without the other will cause the Logitech driver to
silently fail when connecting Logitech devices.

Change-Id: I92ed2b6803537d9da6eed7fcada8f329cb4469a2
Signed-off-by: Michael Wright <michaelwr@google.com>
10 years agogpiolib: safer implementation of desc_to_gpio()
Alexandre Courbot [Fri, 4 Oct 2013 17:59:57 +0000 (10:59 -0700)]
gpiolib: safer implementation of desc_to_gpio()

The current implementation of desc_to_gpio() relies on the chip pointer
to be set to a valid value in order to compute the GPIO number. This
was done in the hope that we can get rid of the gpio_desc global array,
but this is not happening anytime soon.

This patch reimplements desc_to_gpio() in a fashion similar to that of
gpio_to_desc(). As a result, desc_to_gpio(gpio_to_desc(gpio)) == gpio is
now always true. This allows to call desc_to_gpio() on non-initialized
descriptors as some error-handling code currently does.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Reported-by: Dr. H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
10 years agoion: Fix build warning
John Stultz [Fri, 13 Dec 2013 03:09:47 +0000 (19:09 -0800)]
ion: Fix build warning

Add #include <linux/device.h> to fix the following warning seen
with gcc 4.7.3:

In file included from drivers/staging/android/ion/ion_heap.c:26:0:
drivers/staging/android/ion/ion_priv.h:358:21: warning: ‘struct device’ declared inside parameter list [enabled by default]
drivers/staging/android/ion/ion_priv.h:358:21: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]

Change-Id: Icc249b32d877a5b76b1669c99bef2b05d9e322da
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agoion: remove ion_user_handle_t from ion_test.h
Colin Cross [Tue, 17 Dec 2013 00:33:00 +0000 (16:33 -0800)]
ion: remove ion_user_handle_t from ion_test.h

ion_test.h should not define ion_user_handle_t, and defining it
causes a warning:
In file included from drivers/staging/android/ion/ion_test.c:31:
drivers/staging/android/ion/../uapi/ion_test.h:23: error: redefinition of typedef 'ion_user_handle_t'
drivers/staging/android/ion/../uapi/ion.h:23: note: previous declaration of 'ion_user_handle_t' was here

Change-Id: I541897745a5ff128790a7e51b23f3034f5d3d6d9
Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: Don't allow building ION as a module.
John Stultz [Sat, 14 Dec 2013 20:06:45 +0000 (12:06 -0800)]
ion: Don't allow building ION as a module.

ION doesn't export the proper symbols for it to be a module. This
causes build issues when ION is configured as a module.

Since Andorid kernels rarely use modules (I think recent policy
requires no modules?), go ahead and set the ION config to a bool
from the tristate option.

If folks decide ION as a module is important, we will have to go
through and export the various needed symbols.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agotimerfd: support CLOCK_BOOTTIME clock
Greg Hackmann [Fri, 13 Dec 2013 21:02:31 +0000 (13:02 -0800)]
timerfd: support CLOCK_BOOTTIME clock

Add CLOCK_BOOTTIME support to timerfd

Change-Id: I14dee6d1104f15a05f463a632268ac4564753faf
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agoandroid: configs: require TCPMSS, remove SCHED_TRACER and TIMER_STATS
JP Abgrall [Sat, 23 Nov 2013 01:29:57 +0000 (17:29 -0800)]
android: configs: require TCPMSS, remove SCHED_TRACER and TIMER_STATS

TCPMSS is required for the Android Vpn service to correctly
handle the MTU on tun/ppp devices.  Bug: 11579326
We don't really need SCHED_TRACER and the TIMER_STATS.

Change-Id: I10c5767a6324a496713752d4fe9eff361dc8e06a
(cherry picked from commit 23f01e8e81f3c53985958fa291b39c84293ad047)

10 years agoion: Improve ION config description
John Stultz [Fri, 8 Nov 2013 03:58:41 +0000 (19:58 -0800)]
ion: Improve ION config description

Mostly just to quiet checkpatch warnings, be more verbose
in describing the ION config option.

Change-Id: I194235f1a68623dca15ae6e658fc99d00943a827
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agoion: Cleanup whitespace issues and other checkpatch problems
John Stultz [Fri, 8 Nov 2013 03:51:09 +0000 (19:51 -0800)]
ion: Cleanup whitespace issues and other checkpatch problems

Just some simple cleanups to address whitespace issues and
other issues found w/ checkpatch.

Change-Id: I181444505627894b8f3bbf59192703b0f65736ee
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agoandroid: configs: Reorder config fragments, update README
JP Abgrall [Fri, 22 Nov 2013 22:07:03 +0000 (14:07 -0800)]
android: configs: Reorder config fragments, update README

Change-Id: I5ee4b794dcc00f74f26562e49a406ea292af63ee
(cherry picked from commit 9ebedefd06142c9bc812bfa23401031525002a76)

10 years agoion: fix bugs in cma heap
Colin Cross [Wed, 27 Nov 2013 23:53:21 +0000 (15:53 -0800)]
ion: fix bugs in cma heap

Implement ion_cma_unmap_kernel, ion will call it unconditionally.
Use correct gfp flags when calling dma_alloc_coherent so it doesn't
try to use atomic DMA memory.
Check for invalid alignment when allocating.
Reject cached allocations - the cpu address returned by
dma_alloc_coherent is always going to be an uncached mapping, so
map_kernel will not see data written by a cached userspace mapping.

Change-Id: I2ea03f28fae3749f6de0b89700b69da3845926ea
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: add alignment check to chunk heap
Colin Cross [Wed, 27 Nov 2013 23:53:01 +0000 (15:53 -0800)]
ion: add alignment check to chunk heap

Change-Id: I4be12b9545a81f9b46339a905f00e1e64896b3ed
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: add helper to zero contiguous region of pages
Colin Cross [Wed, 27 Nov 2013 23:51:02 +0000 (15:51 -0800)]
ion: add helper to zero contiguous region of pages

Add ion_heap_pages_zero for ion heaps to use to zero pages
during initialization or allocation, when a struct ion_buffer
may not be available.  Use it from the chunk heap and carveout
heaps.

Change-Id: Ic6c921943a8820cf9896da5164f2d9794d0fe91f
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: carveout heap: zero buffers on free, fix memory leak
Colin Cross [Wed, 27 Nov 2013 05:36:54 +0000 (21:36 -0800)]
ion: carveout heap: zero buffers on free, fix memory leak

The carveout heap wasn't zeroing its buffers after use.
Create the sg_table during allocate instead of map_dma, to allow
using the sg_table during free, and call ion_heap_buffer_zero
during free.  Also fixes a missing kfree when destroying the
table.

Change-Id: I318a8493cce32580250884cae336dd2e2c28e73b
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: fix sparse warnings
Colin Cross [Wed, 27 Nov 2013 05:25:47 +0000 (21:25 -0800)]
ion: fix sparse warnings

Fix sparse warnings in ion.

Change-Id: Icbadf2ca53bea20914f608f619568629c178eae3
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: use alloc_pages in system contig heap
Colin Cross [Tue, 26 Nov 2013 23:35:29 +0000 (15:35 -0800)]
ion: use alloc_pages in system contig heap

There is no reason to use kzalloc, just call alloc_pages directly.
Change the GFP from GFP_KERNEL to include __GFP_HIGH, to allow it
to return contiguous pages from highmem.  virt_to_* functions
aren't valid on highmem pages, so store the struct page * in an
sg_table in buffer->priv_virt like most other heaps, and replace
virt_to_* with page_to_*.

Change-Id: Ida78888b101f080883716e1fa5038dfc4dbabd16
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: allow cached mappings of chunk and system heap buffers
Colin Cross [Tue, 26 Nov 2013 23:33:33 +0000 (15:33 -0800)]
ion: allow cached mappings of chunk and system heap buffers

Now that ion_vm_fault uses vm_insert_pfn instead of vm_insert_page
cached buffers can be supported in any heap.  Remove the checks
in the chunk and system heaps.

Change-Id: I371a44c400ed8a342c3b0eed90d0fb7060537697
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: remove ion_heap_alloc_pages
Colin Cross [Tue, 26 Nov 2013 23:25:59 +0000 (15:25 -0800)]
ion: remove ion_heap_alloc_pages

Now that ion_vm_fault doesn't need a struct page with a nonzero
refcount, there is no need allocate heap memory for cached pages using
split_page.  Remove the ion_heap_alloc_pages and ion_heap_free_pages
helpers in favor of direct calls to alloc_pages and __free_pages,
and remove the special handling in the system heap.

Change-Id: I5966a798f48df2d56642e662a69c1495944f6509
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: use vm_insert_pfn for faulted pages
Colin Cross [Tue, 26 Nov 2013 23:05:46 +0000 (15:05 -0800)]
ion: use vm_insert_pfn for faulted pages

Most ion userspace mappings are created with remap_pfn_range.  Use
vm_insert_pfn instead of vm_insert_page to make faulted cached
mappings look more like uncached mappings.

Change-Id: I9ec5cad3fef54f3b80be8b306d7ff2f1fe3f0e66
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: check return value from remap_pfn_range
Colin Cross [Tue, 26 Nov 2013 23:34:50 +0000 (15:34 -0800)]
ion: check return value from remap_pfn_range

Check the return value of remap_pfn_range and return an error if
it fails.

Change-Id: I206cf95a24607ebe1c80274e3ed15cc7c076d007
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: free low memory from page pools first
Colin Cross [Fri, 22 Nov 2013 02:56:37 +0000 (18:56 -0800)]
ion: free low memory from page pools first

When the shrinkers are called with GFP_HIGH free low memory first,
it is more important to have free than high memory.

Change-Id: I7ad8a9c133830f04d429c3d87b781b3e862ccedb
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: optimize ion_heap_buffer_zero
Colin Cross [Mon, 25 Nov 2013 21:32:51 +0000 (13:32 -0800)]
ion: optimize ion_heap_buffer_zero

ion_heap_buffer_zero can spend a long time in unmap_kernel_range
if it has to broadcast a tlb flush to every cpu for every page.
Modify it to batch pages into a larger region to clear using a
single mapping.  This may cause the mapping size to change if
the buffer size is not a multiple of the mapping size, so
switch to allocating the address space for each chunk.  This
allows us to use vm_map_ram to handle the allocation and mapping
together.

The number of pages to zero using a single mapping is set to 32
to hit the fastpath in vm_map_ram.

Change-Id: I1accfe67b285cbc9e95e387bea4246864197827d
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: add alignment check to carveout heap
Colin Cross [Tue, 26 Nov 2013 21:43:29 +0000 (13:43 -0800)]
ion: add alignment check to carveout heap

Change-Id: I25c752b3eacb48cccea5be2df319634b3affd331
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: drop dependency on ARM
Colin Cross [Sat, 23 Nov 2013 06:48:42 +0000 (22:48 -0800)]
ion: drop dependency on ARM

Ion will compile and run on other platforms now, remove the
dependency on ARM.

Change-Id: I9da0ab686708bdab575a021031392b4402cce090
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: Fix two small issues in system_heap allocation
John Stultz [Fri, 22 Nov 2013 23:36:27 +0000 (15:36 -0800)]
ion: Fix two small issues in system_heap allocation

In testing ion system heap allocations, I ran across two issues:

1) Not k*z*allocing the sg table. This can cause trouble if
we end up trying call sg_alloc_table() with too many entries,
then sg_alloc_table() internally fails and tries to free what it
thinks is internal table structure, which causes bad pointer
traversals.

2) The second list_for_each_entry probably should be _safe,
since I was seeing  strange lock warnings and oopses on occasion.
This seems to resolve it, but could use some extra checking.

Change-Id: I59d4c90104a8cf23dc4ae814d0b17348f1b68ac0
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agogpu: ion: fix use-after-free in ion_heap_freelist_drain
Mitchel Humpherys [Tue, 6 Aug 2013 18:19:42 +0000 (11:19 -0700)]
gpu: ion: fix use-after-free in ion_heap_freelist_drain

The `buffer' variable is being used after being freed. Fix this.

Change-Id: Iea3471fa7dc7535bbf0620c1639fea2008d7cf19
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
10 years agoion: clean up ioctls
Colin Cross [Sat, 9 Nov 2013 00:55:35 +0000 (16:55 -0800)]
ion: clean up ioctls

Convert the ion ioctls to use _IOW instead of _IOWR where
appropriate, and factor out the copy_from_user and copy_to_user
based on the _IOC_DIR bits.  For the existing incorrect ioctls,
add a function to wrap _IOC_DIR to return the corrected value.

Change-Id: I3cc34c84b9c52305bdbec27a9224447b102fadcd
Signed-off-by: Colin Cross <ccross@android.com>
10 years agogpu: ion: remove unnecessary function from system heap
Colin Cross [Thu, 7 Nov 2013 20:18:57 +0000 (12:18 -0800)]
gpu: ion: remove unnecessary function from system heap

ion_system_contig_heap buffers have an sglist, just call
ion_heap_map_user to map it.

Change-Id: I6dea383955834613fa8833659b31533c957c2b0b
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: fix printk warnings
Colin Cross [Thu, 19 Sep 2013 14:20:23 +0000 (09:20 -0500)]
ion: fix printk warnings

Use %z for size_t and %pa for dma_addr_t to avoid warnings in printks.

Change-Id: I2c72874acd0b69cb35fca691928783817deb9394
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: don't use phys_to_page or __phys_to_pfn
Colin Cross [Thu, 19 Sep 2013 15:13:53 +0000 (10:13 -0500)]
ion: don't use phys_to_page or __phys_to_pfn

phys_to_page and __phys_to_pfn don't exist on all platforms.
Use a combination of pfn_to_page, PFN_DOWN, page_to_pfn, and
virt_to_page to get the same results.

Change-Id: I53cef26059800bc8b7fb85ae458741574c97c257
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: don't use __arm_ioremap to map pages
Colin Cross [Thu, 19 Sep 2013 15:12:05 +0000 (10:12 -0500)]
ion: don't use __arm_ioremap to map pages

ion_heap_map_kernel already implements mapping a scatterlist of
pages into the kernel, and all heaps are required to have struct
pages associated with them, so delete the functions that use
__arm_ioremap and use ion_heap_map_kernel instead.

Change-Id: Ia2dfd8d8c6e719d7d2f68dd4c458826fdb938260
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: update idr to avoid deprecated apis
Colin Cross [Thu, 19 Sep 2013 19:54:56 +0000 (14:54 -0500)]
ion: update idr to avoid deprecated apis

Use idr_alloc instead if idr_pre_get/idr_get_new_above, and
remove idr_remove_all.

Change-Id: I675b789879549bd3767ed3ef2016cf108eb622d2
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: add test device for unit tests to interact with dma_bufs
Colin Cross [Sat, 9 Nov 2013 00:32:47 +0000 (16:32 -0800)]
ion: add test device for unit tests to interact with dma_bufs

Add a /dev/ion-test device that will be created if CONFIG_ION_TEST
is set.  The device accepts a dma_buf fd and allows reading and
writing to the backing memory using DMA-like apis or kernel mapping
apis.  Can be used to test the dma_buf mapping ops, including
the ion implementations, from userspace.

Change-Id: I30703ba69cd75bdfe7767ac642e5f0cacd8d0478
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: check invalid values in ion_system_heap
Colin Cross [Wed, 13 Nov 2013 22:46:06 +0000 (14:46 -0800)]
ion: check invalid values in ion_system_heap

ion_system_heap can only satisfy page alignment, and
ion_system_contig_heap can only satisify alignment to the
allocation size.  Neither can support faulting user mappings
because they use slab pages.

Change-Id: I895c2d4184c672f647f83a17aeb862985dc92f2c
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoARM: fiq_glue: Add custom fiq return handler api.
Arve Hjønnevåg [Tue, 25 Jun 2013 01:02:05 +0000 (18:02 -0700)]
ARM: fiq_glue: Add custom fiq return handler api.

Change-Id: I5ff2764e85151ca0a88576542fda07c2d33dd065
Signed-off-by: Arve Hjønnevåg <arve@android.com>
10 years agonetfilter: xt_qtaguid: fix memory leak in seq_file handlers
Greg Hackmann [Thu, 5 Dec 2013 01:39:27 +0000 (17:39 -0800)]
netfilter: xt_qtaguid: fix memory leak in seq_file handlers

Change-Id: I15b21230d52479d008a00d9e2191dda020f00925
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agovideo: adf: fix fbdev blank -> dpms state mapping
Greg Hackmann [Fri, 22 Nov 2013 21:50:24 +0000 (13:50 -0800)]
video: adf: fix fbdev blank -> dpms state mapping

Change-Id: I96132a1b7275d389a6d0ba8899c6be838b63c422
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agovideo: adf: validate dpms state passed to blank
Greg Hackmann [Wed, 20 Nov 2013 20:10:35 +0000 (12:10 -0800)]
video: adf: validate dpms state passed to blank

Change-Id: I3a4228d50fc4a2553b3e92e5675a94cbc6e71b8a
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agovideo: adf: fix ADF_MAX_ATTACHMENTS declaration
Greg Hackmann [Mon, 11 Nov 2013 22:31:12 +0000 (14:31 -0800)]
video: adf: fix ADF_MAX_ATTACHMENTS declaration

Userspace-facing ADF_MAX_ATTACHMENTS must be in terms of
userspace-facing struct adf_attachment_config

Change-Id: Iaaddcd6366f13b3e52eb3911efcfff8a61e0b225
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agovideo: adf: remove PAGE_SIZE from userspace-facing header
Greg Hackmann [Wed, 20 Nov 2013 22:02:09 +0000 (14:02 -0800)]
video: adf: remove PAGE_SIZE from userspace-facing header

Systems may define PAGE_SIZE in userspace limits.h but don't have to.
PAGE_SIZE was picked as an arbitrary "reasonable" limit so just use 4096
instead.

Change-Id: I9555e39aba64a3a70f61eb6ded2a4129ab236ce0
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agovideo: adf: make device node names less hierarchical
Greg Hackmann [Thu, 7 Nov 2013 18:12:00 +0000 (10:12 -0800)]
video: adf: make device node names less hierarchical

adf/foobar/device -> adf0
adf/foobar/interface1 -> adf-interface0.1
adf/foobar/overlay-engine1 -> adf-overlay-engine0.1

Change-Id: I7af7f84ce3f101ecb02f448070c200ff3e03f2ec
Signed-off-by: Greg Hackmann <ghackmann@google.com>
10 years agoion: convert sg_dma_len(sg) to sg->length
Colin Cross [Tue, 12 Nov 2013 23:28:08 +0000 (15:28 -0800)]
ion: convert sg_dma_len(sg) to sg->length

ion is always dealing with the allocation and not the mapping,
so it should always be using sg->length and not sg->dma_length.

Change-Id: Id9b07f1196b2bafe04636fa1aa46dfc84d003cf0
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: fix dma APIs
Colin Cross [Wed, 18 Sep 2013 17:30:20 +0000 (12:30 -0500)]
ion: fix dma APIs

__dma_page_cpu_to_dev is a private ARM api that is not available
on 3.10 and was never available on other architectures.  We can
get the same behavior by calling dma_sync_sg_for_device with a
scatterlist containing a single page.  It's still not quite a
kosher use of the dma apis, we still conflate physical addresses
with bus addresses, but it should at least compile on all
platforms, and work on any platform that doesn't have a physical
to bus address translation.

Change-Id: I8451c2dae4bf85841015c016640684ac28430a5a
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: fix crash when alloc len is -1
Colin Cross [Wed, 13 Nov 2013 22:44:53 +0000 (14:44 -0800)]
ion: fix crash when alloc len is -1

If userspace passes a length between -4095 and -1 to allocate it
will pass the len != 0 check, but when len is page aligned it will
be 0.  Check len after page aligning.

Drop the warning as well, userspace shouldn't be able to trigger
a warning in the kernel.

Change-Id: I96c7142637638991f3a9af9be7cfbb50f79f3803
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: hold reference to handle after ion_uhandle_get
Colin Cross [Wed, 6 Nov 2013 00:51:27 +0000 (16:51 -0800)]
ion: hold reference to handle after ion_uhandle_get

commit 1262ab1846cf76f7549c66ef709120dbfbe6d49f (ion: replace
userspace handle cookies with idr) broke the locking in ion.
The ION_IOC_FREE and ION_IOC_MAP ioctls were relying on
ion_handle_validate to detect the case where a call raced
with another ION_IOC_FREE which may have freed the struct
ion_handle.

Rename ion_uhandle_get to ion_handle_get_by_id, and have it
take the client lock and return with an extra reference to
the handle.  Make each caller put its reference once it
is done with the handle.

Also modify users of ion_handle_validate to continue to hold
the client lock after calling ion_handle_validate until
they are done with the handle, and warn if ion_handle_validate
is called without the client lock held.

Change-Id: I56da5624fca3bed4ee24806b6ec39de903543341
Signed-off-by: Colin Cross <ccross@android.com>
10 years agoion: Fix compat support to use proper compat ioctl numbers
John Stultz [Fri, 15 Nov 2013 00:25:08 +0000 (16:25 -0800)]
ion: Fix compat support to use proper compat ioctl numbers

The compat support added to ion didn't provide compat ioctl numbers
(who's value depends on the compat structure size). So 32bit
applications would get an error when trying to make ioctl calls.

This patch adds the needed COMPAT_ macros and uses them in the
compat_ion_ioctl, translating them to their non-compat cmd when
calling the normal ioctl call.

Change-Id: I53636d4ec46d8dc5e694697aaf2d62b98bd78cb1
Signed-off-by: John Stultz <john.stultz@linaro.org>
10 years agoARM: Fix "Make low-level printk work" to use a separate config option
Arve Hjønnevåg [Sat, 15 Jun 2013 02:54:40 +0000 (19:54 -0700)]
ARM: Fix "Make low-level printk work" to use a separate config option

Signed-off-by: Arve Hjønnevåg <arve@android.com>
10 years agoARM: Fix dtb list when DTB_IMAGE_NAMES is empty
Benoit Goby [Fri, 8 Nov 2013 23:24:19 +0000 (15:24 -0800)]
ARM: Fix dtb list when DTB_IMAGE_NAMES is empty

In the 3.10 kernel, dtb-y is not defined in Makefile.boot anymore
but in dts/Makefile, so it needs to be included too.

Change-Id: I6d6fccf933709bcb6220ce8f12b4b9e2a7c40d63
Signed-off-by: Benoit Goby <benoit@android.com>
10 years agoanonymous vma names: fix build with !MMU
Colin Cross [Wed, 30 Oct 2013 20:17:34 +0000 (13:17 -0700)]
anonymous vma names: fix build with !MMU

Disable PR_SET_VMA when building with !MMU

Change-Id: I896b6979b99aa61df85caf4c3ec22eb8a8204e64
Signed-off-by: Colin Cross <ccross@android.com>
10 years agomm: fix anon vma naming
Colin Cross [Wed, 30 Oct 2013 20:14:12 +0000 (13:14 -0700)]
mm: fix anon vma naming

Fix two bugs caused by merging anon vma_naming, a typo in
mempolicy.c and a bad merge in sys.c.

Change-Id: Ia4ced447d50573e68195e95ea2f2b4d9456b8a90
Signed-off-by: Colin Cross <ccross@android.com>
10 years agodrivers: staging: android: split uapi out of sync.h and sw_sync.h
Colin Cross [Thu, 7 Nov 2013 21:46:41 +0000 (13:46 -0800)]
drivers: staging: android: split uapi out of sync.h and sw_sync.h

Move the userspace interfaces of sync.h and sw_sync.h to
drivers/staging/android/uapi/

Change-Id: I3b2598b37385bb993bd03f5faa98a8e196befe45
Signed-off-by: Colin Cross <ccross@android.com>
10 years agodrivers: staging: android: split uapi out of binder.h
Colin Cross [Thu, 7 Nov 2013 21:46:41 +0000 (13:46 -0800)]
drivers: staging: android: split uapi out of binder.h

Move the userspace interface of binder.h to
drivers/staging/android/uapi/binder.h.

Change-Id: I2e56ba89ade5e1f33b121e6ecd456392d588a14e
Signed-off-by: Colin Cross <ccross@android.com>
10 years agodrivers: staging: android: split uapi out of ashmem.h
Colin Cross [Thu, 7 Nov 2013 21:46:41 +0000 (13:46 -0800)]
drivers: staging: android: split uapi out of ashmem.h

Move the userspace interface of ashmem.h to
drivers/staging/android/uapi/ashmem.h

Change-Id: I60f5baa4ce8e2425262a406f2733c089ec55aa72
Signed-off-by: Colin Cross <ccross@android.com>
10 years agodrivers: staging: android: split uapi out of android_alarm.h
Colin Cross [Thu, 7 Nov 2013 21:38:57 +0000 (13:38 -0800)]
drivers: staging: android: split uapi out of android_alarm.h

Move the userspace interface of android_alarm.h to
drivers/staging/android/uapi/android_alarm.h

Change-Id: Ieb96e8e9bf742786efc4e248e6a242dab8199ca3
Signed-off-by: Colin Cross <ccross@android.com>
10 years agonet: move PPPoLAC and PPPoPNS headers to uapi
Colin Cross [Thu, 7 Nov 2013 21:19:34 +0000 (13:19 -0800)]
net: move PPPoLAC and PPPoPNS headers to uapi

Move the entire contents of the linux/if_pppolac.h and
linux/if_pppopns.h headers to uapi, they only contain userspace
interfaces.

Change-Id: I3cfed7f2ae400b53269a1f59144aa3dbc30ae0b5
Signed-off-by: Colin Cross <ccross@android.com>