Staging updates from the Android tree
cover Staging updates from the Android tree
I recently went through the AOSP common.git android/3.10 tree to try to pull fixes that haven't been submitted upstream. I've cherry picked those patches and wanted to submit them here for review, and for hopeful inclusion into staging for 3.15.
In most cases the patches cherry-picked right over. In a few cases, there were collisions due to trivial changes and cleanups like spelling fixes. However, the "ion: Move shrinker out of heaps" patch required more complicated merge, due to the shrinker api change upstream in 3.12. Things build and appear to work, but I'd appreciate extra review there.
Anyway, please let me know if there's any feedback or suggestions.
thanks
-john
Alistair Strachan (1):
staging: sync: Fix a race condition between release_obj and print_obj
Colin Cross (6):
staging: android: Split uapi out of android_alarm.h
staging: android: Split uapi out of ashmem.h
staging: android: split uapi out of sync.h and sw_sync.h
staging: android: Split uapi out of binder.h
staging: ion: Fix overflow and list bugs in system heap
staging: ion: Move shrinker out of heaps
Greg Hackmann (1):
staging: sw_sync: Add stubs for kernels without CONFIG_SW_SYNC
Laura Abbott (2):
staging: ion: Fix debugfs handling of multiple kernel clients
staging: ion: Fix ION_IOC_FREE compat ioctl
Mitchel Humpherys (4):
staging: ion: Create separate heap and client debugfs directories
staging: ion: Store a copy of the client name on client creation
staging: ion: Make sure all clients are exposed in debugfs
staging: ion: Add private buffer flag to skip page pooling on free
Prakash Kamliya (1):
staging: sync: Signal pt before sync_timeline object gets destroyed
Todd Poynor (1):
staging: ashmem: Avoid deadlock between read and mmap calls
drivers/staging/android/android_alarm.h | 44 +--- drivers/staging/android/ashmem.c | 45 ++-- drivers/staging/android/ashmem.h | 30 +-- drivers/staging/android/binder.h | 306 +----------------------- drivers/staging/android/ion/compat_ion.c | 26 +- drivers/staging/android/ion/ion.c | 121 ++++++++-- drivers/staging/android/ion/ion_heap.c | 65 ++++- drivers/staging/android/ion/ion_page_pool.c | 8 +- drivers/staging/android/ion/ion_priv.h | 63 ++++- drivers/staging/android/ion/ion_system_heap.c | 90 ++----- drivers/staging/android/sw_sync.h | 37 +-- drivers/staging/android/sync.c | 14 +- drivers/staging/android/sync.h | 86 +------ drivers/staging/android/uapi/android_alarm.h | 62 +++++ drivers/staging/android/uapi/ashmem.h | 47 ++++ drivers/staging/android/uapi/binder.h | 330 ++++++++++++++++++++++++++ drivers/staging/android/uapi/sw_sync.h | 32 +++ drivers/staging/android/uapi/sync.h | 97 ++++++++ 18 files changed, 895 insertions(+), 608 deletions(-) create mode 100644 drivers/staging/android/uapi/android_alarm.h create mode 100644 drivers/staging/android/uapi/ashmem.h create mode 100644 drivers/staging/android/uapi/binder.h create mode 100644 drivers/staging/android/uapi/sw_sync.h create mode 100644 drivers/staging/android/uapi/sync.h
Signature · 1 line
1.8.3.2
PATCH 1/16 staging: android: Split uapi out of android_alarm.h
From: Colin Cross <[email protected]>
Move the userspace interface of android_alarm.h to drivers/staging/android/uapi/android_alarm.h
--- drivers/staging/android/android_alarm.h | 44 +------------------- drivers/staging/android/uapi/android_alarm.h | 62 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 42 deletions(-) create mode 100644 drivers/staging/android/uapi/android_alarm.h
drivers/staging/android/android_alarm.h +2 -42
@@ -16,50 +16,10 @@#ifndef _LINUX_ANDROID_ALARM_H#define _LINUX_ANDROID_ALARM_H -#include <linux/ioctl.h> -#include <linux/time.h> #include <linux/compat.h> +#include <linux/ioctl.h> -enum android_alarm_type { -/* return code bit numbers or set alarm arg */ -ANDROID_ALARM_RTC_WAKEUP , -ANDROID_ALARM_RTC , -ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP , -ANDROID_ALARM_ELAPSED_REALTIME , -ANDROID_ALARM_SYSTEMTIME , - -ANDROID_ALARM_TYPE_COUNT , - -/* return code bit numbers */ -/* ANDROID_ALARM_TIME_CHANGE = 16 */ -}; - -enum android_alarm_return_flags { -ANDROID_ALARM_RTC_WAKEUP_MASK =1U <<ANDROID_ALARM_RTC_WAKEUP , -ANDROID_ALARM_RTC_MASK =1U <<ANDROID_ALARM_RTC , -ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK = -1U <<ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP , -ANDROID_ALARM_ELAPSED_REALTIME_MASK = -1U <<ANDROID_ALARM_ELAPSED_REALTIME , -ANDROID_ALARM_SYSTEMTIME_MASK =1U <<ANDROID_ALARM_SYSTEMTIME , -ANDROID_ALARM_TIME_CHANGE_MASK =1U <<16 -}; - -/* Disable alarm */ -#define ANDROID_ALARM_CLEAR (type) _IO('a', 0 | ((type) << 4)) - -/* Ack last alarm and wait for next */ -#define ANDROID_ALARM_WAIT _IO('a', 1) - -#define ALARM_IOW (c, type, size) _IOW('a', (c) | ((type) << 4), size) -/* Set alarm */ -#define ANDROID_ALARM_SET (type) ALARM_IOW(2, type, struct timespec) -#define ANDROID_ALARM_SET_AND_WAIT (type) ALARM_IOW(3, type, struct timespec) -#define ANDROID_ALARM_GET_TIME (type) ALARM_IOW(4, type, struct timespec) -#define ANDROID_ALARM_SET_RTC _IOW('a', 5, struct timespec) -#define ANDROID_ALARM_BASE_CMD (cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) -#define ANDROID_ALARM_IOCTL_TO_TYPE (cmd) (_IOC_NR(cmd) >> 4) - +#include "uapi/android_alarm.h" #ifdef CONFIG_COMPAT #define ANDROID_ALARM_SET_COMPAT (type) ALARM_IOW(2, type, \
drivers/staging/android/uapi/android_alarm.h new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 2/16 staging: android: Split uapi out of ashmem.h
In reply to John StultzFrom: Colin Cross <[email protected]>
Move the userspace interface of ashmem.h todrivers/staging/android/uapi/ashmem.h
--- drivers/staging/android/ashmem.h | 30 +--------------------- drivers/staging/android/uapi/ashmem.h | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 drivers/staging/android/uapi/ashmem.h
drivers/staging/android/ashmem.h +1 -29
@@ -16,35 +16,7 @@#include <linux/ioctl.h> #include <linux/compat.h> -#define ASHMEM_NAME_LEN 256 - -#define ASHMEM_NAME_DEF "dev/ashmem" - -/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ -#define ASHMEM_NOT_PURGED 0 -#define ASHMEM_WAS_PURGED 1 - -/* Return values from ASHMEM_GET_PIN_STATUS: Is the mapping pinned? */ -#define ASHMEM_IS_UNPINNED 0 -#define ASHMEM_IS_PINNED 1 - -struct ashmem_pin { -__u32 offset;/* offset into region, in bytes, page-aligned */ -__u32 len;/* length forward from offset, in bytes, page-aligned */ -}; - -#define __ASHMEMIOC 0x77 - -#define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) -#define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) -#define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) -#define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) -#define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) -#define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) -#define ASHMEM_PIN _IOW(__ASHMEMIOC, 7, struct ashmem_pin) -#define ASHMEM_UNPIN _IOW(__ASHMEMIOC, 8, struct ashmem_pin) -#define ASHMEM_GET_PIN_STATUS _IO(__ASHMEMIOC, 9) -#define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) +#include "uapi/ashmem.h" /* support of 32bit userspace on 64bit platforms */ #ifdef CONFIG_COMPAT
drivers/staging/android/uapi/ashmem.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 3/16 staging: android: split uapi out of sync.h and sw_sync.h
In reply to John StultzFrom: Colin Cross <[email protected]>
Move the userspace interfaces of sync.h and sw_sync.h to drivers/staging/android/uapi/
--- drivers/staging/android/sw_sync.h | 20 +------ drivers/staging/android/sync.h | 86 +----------------------------- drivers/staging/android/uapi/sw_sync.h | 32 +++++++++++ drivers/staging/android/uapi/sync.h | 97 ++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 102 deletions(-) create mode 100644 drivers/staging/android/uapi/sw_sync.h create mode 100644 drivers/staging/android/uapi/sync.h
drivers/staging/android/sw_sync.h +2 -18
@@ -18,10 +18,9 @@#define _LINUX_SW_SYNC_H#include <linux/types.h> - -#ifdef __KERNEL__ - +#include <linux/kconfig.h> #include "sync.h" +#include "uapi/sw_sync.h" struct sw_sync_timeline {struct sync_timeline obj;
@@ -40,19 +39,4 @@ void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);struct sync_pt *sw_sync_pt_create (struct sw_sync_timeline *obj,u32 value); -#endif /* __KERNEL __ */ - -struct sw_sync_create_fence_data { -__u32 value; -char name[32 ]; -__s32 fence;/* fd of new fence */ -}; - -#define SW_SYNC_IOC_MAGIC 'W' - -#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\ - struct sw_sync_create_fence_data) -#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) - -#endif /* _LINUX_SW_SYNC_H */
drivers/staging/android/sync.h +2 -84
102 lines not on this page · raw message
drivers/staging/android/uapi/sw_sync.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2012 Google, Inc. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef _UAPI_LINUX_SW_SYNC_H +#define _UAPI_LINUX_SW_SYNC_H + +#include <linux/types.h> + +struct sw_sync_create_fence_data { +__u32 value; +char name[32 ]; +__s32 fence;/* fd of new fence */ +}; + +#define SW_SYNC_IOC_MAGIC 'W' + +#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\ + struct sw_sync_create_fence_data) +#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) + +#endif /* _UAPI_LINUX_SW_SYNC_H */
drivers/staging/android/uapi/sync.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 4/16 staging: android: Split uapi out of binder.h
In reply to John StultzFrom: Colin Cross <[email protected]>
Move the userspace interface of binder.h todrivers/staging/android/uapi/binder.h.
[jstultz: Worked out the collisions from some of the type changes made upstream. Also minor commit subject tweak]
--- drivers/staging/android/binder.h | 306 +------------------------------ drivers/staging/android/uapi/binder.h | 330 ++++++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+), 305 deletions(-) create mode 100644 drivers/staging/android/uapi/binder.h
drivers/staging/android/binder.h +1 -305
@@ -20,311 +20,7 @@#ifndef _LINUX_BINDER_H#define _LINUX_BINDER_H -#include <linux/ioctl.h> - -#define B_PACK_CHARS (c1, c2, c3, c4) \ - ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) -#define B_TYPE_LARGE 0x85 - -enum { -BINDER_TYPE_BINDER =B_PACK_CHARS ('s' ,'b' ,'*' ,B_TYPE_LARGE ), -BINDER_TYPE_WEAK_BINDER =B_PACK_CHARS ('w' ,'b' ,'*' ,B_TYPE_LARGE ), -BINDER_TYPE_HANDLE =B_PACK_CHARS ('s' ,'h' ,'*' ,B_TYPE_LARGE ), -BINDER_TYPE_WEAK_HANDLE =B_PACK_CHARS ('w' ,'h' ,'*' ,B_TYPE_LARGE ), -BINDER_TYPE_FD =B_PACK_CHARS ('f' ,'d' ,'*' ,B_TYPE_LARGE ), -}; - -enum { -FLAT_BINDER_FLAG_PRIORITY_MASK =0xff , -FLAT_BINDER_FLAG_ACCEPTS_FDS =0x100 , -}; - -/* -* This is the flattened representation of a Binder object for transfer -* between processes. The 'offsets' supplied as part of a binder transaction -* contains offsets into the data where these structures occur. The Binder -* driver takes care of re-writing the structure type and data as it moves -* between processes. -*/ -struct flat_binder_object { -/* 8 bytes for large_flat_header. */ -__u32 type; -__u32 flags; - -/* 8 bytes of data. */ -union { -void __user *binder;/* local object */ -__u32 handle;/* remote object */ - }; - -/* extra data associated with local object */ -void __user *cookie; -}; - -/* -* On 64-bit platforms where user code may run in 32-bits the driver must -* translate the buffer (and local binder) addresses appropriately. -*/ - -struct binder_write_read { -size_t write_size;/* bytes to write */ -size_t write_consumed;/* bytes consumed by driver */ -unsigned long write_buffer; -size_t read_size;/* bytes to read */ -size_t read_consumed;/* bytes consumed by driver */ -unsigned long read_buffer; -}; - -/* Use with BINDER_VERSION, driver fills in fields. */ -struct binder_version { -/* driver protocol version -- increment with incompatible change */ -__s32 protocol_version; -}; - -/* This is the current protocol version. */ -#define BINDER_CURRENT_PROTOCOL_VERSION 7 - -#define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read) -#define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64) -#define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32) -#define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32) -#define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32) -#define BINDER_THREAD_EXIT _IOW('b', 8, __s32) -#define BINDER_VERSION _IOWR('b', 9, struct binder_version) - -/* -* NOTE: Two special error codes you should check for when calling -* in to the driver are: -* -* EINTR -- The operation has been interupted. This should be -* handled by retrying the ioctl() until a different error code -* is returned. -* -* ECONNREFUSED -- The driver is no longer accepting operations -* from your process. That is, the process is being destroyed. -* You should handle this by exiting from your process. Note -* that once this error code is returned, all further calls to -* the driver from any thread will return this same code. -*/ - -enum transaction_flags { -TF_ONE_WAY =0x01 ,/* this is a one-way call: async, no return */ -TF_ROOT_OBJECT =0x04 ,/* contents are the component's root object */ -TF_STATUS_CODE =0x08 ,/* contents are a 32-bit status code */ -TF_ACCEPT_FDS =0x10 ,/* allow replies with file descriptors */ -}; - -struct binder_transaction_data { -/* The first two are only used for bcTRANSACTION and brTRANSACTION, -* identifying the target and contents of the transaction. -*/ -union { -__u32 handle;/* target descriptor of command transaction */ -void *ptr;/* target descriptor of return transaction */ - } target; -void *cookie;/* target object cookie */ -__u32 code;/* transaction command */ - -/* General information about the transaction. */ -__u32 flags; -pid_t sender_pid; -uid_t sender_euid; -size_t data_size;/* number of bytes of data */ -size_t offsets_size;/* number of bytes of offsets */ - -/* If this transaction is inline, the data immediately -* follows here; otherwise, it ends with a pointer to -* the data buffer. -*/ -union { -struct { -/* transaction data */ -const void __user *buffer; -/* offsets from buffer to flat_binder_object structs */ -const void __user *offsets; - } ptr; -__u8 buf[8 ]; - } data; -}; - -struct binder_ptr_cookie { -void *ptr; -void *cookie; -}; - -struct binder_pri_desc { -__s32 priority; -__u32 desc; -}; - -struct binder_pri_ptr_cookie { -__s32 priority; -void *ptr; -void *cookie; -}; - -enum binder_driver_return_protocol { -BR_ERROR =_IOR ('r' ,0 , __s32), -/* -* int: error code -*/ - -BR_OK =_IO ('r' ,1 ), -/* No parameters! */ - - BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data), - BR_REPLY = _IOR('r', 3, struct binder_transaction_data), -/* -* binder_transaction_data: the received command. -*/ - -BR_ACQUIRE_RESULT =_IOR ('r' ,4 , __s32), -/* -* not currently supported -* int: 0 if the last bcATTEMPT_ACQUIRE was not successful. -* Else the remote object has acquired a primary reference. -*/ - -BR_DEAD_REPLY =_IO ('r' ,5 ), -/* -* The target of the last transaction (either a bcTRANSACTION or -* a bcATTEMPT_ACQUIRE) is no longer with us. No parameters. -*/ - -BR_TRANSACTION_COMPLETE =_IO ('r' ,6 ), -/* -* No parameters... always refers to the last transaction requested -* (including replies). Note that this will be sent even for -* asynchronous transactions. -*/ - - BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie), - BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie), - BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie), - BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie), -/* -* void *: ptr to binder -* void *: cookie for binder -*/ - - BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie), -/* -* not currently supported -* int: priority -* void *: ptr to binder -* void *: cookie for binder -*/ - -BR_NOOP =_IO ('r' ,12 ), -/* -* No parameters. Do nothing and examine the next command. It exists -* primarily so that we can replace it with a BR_SPAWN_LOOPER command. -*/ - -BR_SPAWN_LOOPER =_IO ('r' ,13 ), -/* -* No parameters. The driver has determined that a process has no -* threads waiting to service incoming transactions. When a process -* receives this command, it must spawn a new service thread and -* register it via bcENTER_LOOPER. -*/ - -BR_FINISHED =_IO ('r' ,14 ), -/* -* not currently supported -* stop threadpool thread -*/ - - BR_DEAD_BINDER = _IOR('r', 15, void *), -/* -* void *: cookie -*/ - BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, void *), -/* -* void *: cookie -*/ - -BR_FAILED_REPLY =_IO ('r' ,17 ), -/* -* The the last transaction (either a bcTRANSACTION or -* a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters. -*/ -}; - -enum binder_driver_command_protocol { - BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), - BC_REPLY = _IOW('c', 1, struct binder_transaction_data), -/* -* binder_transaction_data: the sent command. -*/ - -BC_ACQUIRE_RESULT =_IOW ('c' ,2 , __s32), -/* -* not currently supported -* int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful. -* Else you have acquired a primary reference on the object. -*/ - - BC_FREE_BUFFER = _IOW('c', 3, void *), -/* -* void *: ptr to transaction data received on a read -*/ - -BC_INCREFS =_IOW ('c' ,4 , __u32), -BC_ACQUIRE =_IOW ('c' ,5 , __u32), -BC_RELEASE =_IOW ('c' ,6 , __u32), -BC_DECREFS =_IOW ('c' ,7 , __u32), -/* -* int: descriptor -*/ - - BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie), - BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie), -/* -* void *: ptr to binder -* void *: cookie for binder -*/ - - BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc), -/* -* not currently supported -* int: priority -* int: descriptor -*/ - -BC_REGISTER_LOOPER =_IO ('c' ,11 ), -/* -* No parameters. -* Register a spawned looper thread with the device. -*/ - -BC_ENTER_LOOPER =_IO ('c' ,12 ), -BC_EXIT_LOOPER =_IO ('c' ,13 ), -/* -* No parameters. -* These two commands are sent as an application-level thread -* enters and exits the binder loop, respectively. They are -* used so the binder can have an accurate count of the number -* of looping threads it has available. -*/ - - BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_ptr_cookie), -/* -* void *: ptr to binder -* void *: cookie -*/ - - BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_ptr_cookie), -/* -* void *: ptr to binder -* void *: cookie -*/ - - BC_DEAD_BINDER_DONE = _IOW('c', 16, void *), -/* -* void *: cookie -*/ -}; +#include "uapi/binder.h" #endif /* _LINUX_BINDER_H */
drivers/staging/android/uapi/binder.h new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 5/16 staging: sw_sync: Add stubs for kernels without CONFIG_SW_SYNC
In reply to John StultzFrom: Greg Hackmann <[email protected]>
Add stubs for kernels without CONFIG_SW_SYNC
--- drivers/staging/android/sw_sync.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/staging/android/sw_sync.h +17 -0
@@ -34,9 +34,26 @@ struct sw_sync_pt { u32 value; }; +#if IS_ENABLED (CONFIG_SW_SYNC )struct sw_sync_timeline *sw_sync_timeline_create (const char *name);void sw_sync_timeline_inc (struct sw_sync_timeline *obj,u32 inc);struct sync_pt *sw_sync_pt_create (struct sw_sync_timeline *obj,u32 value); +#else +static inline struct sw_sync_timeline *sw_sync_timeline_create (const char *name) +{ +return NULL ; +} + +static inline void sw_sync_timeline_inc (struct sw_sync_timeline *obj,u32 inc) +{ +} + +static inline struct sync_pt *sw_sync_pt_create (struct sw_sync_timeline *obj, +u32 value) +{ +return NULL ; +} +#endif /* IS_ENABLED(CONFIG_SW_SYNC) */ #endif /* _LINUX_SW_SYNC_H */
Signature · 1 line
1.8.3.2
PATCH 6/16 staging: sync: Signal pt before sync_timeline object gets destroyed
In reply to John StultzFrom: Prakash Kamliya <[email protected]>
There is a race condition
Assume we have *one* sync_fence object, with *one* sync_pt which belongs to *one* sync_timeline, given this condition, sync_timeline->kref will have two counts, one for sync_timeline (implicit) and another for sync_pt.
Assume following is the situation on CPU
Theead-1 : (Thread which calls sync_timeline_destroy())
-> (some function calls)
-> sync_timeline_destory()
-> sync_timeline_signal() (CPU is inside this
function after putting reference to sync_timeline)
At this time Thread-2 comes and does following
Thread-2 : (fclose on fence fd)
Quoted 1 line
sync_fence_release()-> because offclose()on fence object
-> sync_fence_free()
-> sync_pt_free()
-> kref_put(&pt->parent->kref, sync_timeline_free);
-> sync_timeline_free() (CPU is inside this becausethis time kref will be zero after _put)
Thread-2 will free sync_timeline object before Thread-1 has finished its work inside sync_timeline_signal.
With this change we signals all sync_pt before putting reference to sync_timeline object.
c: Greg KH <[email protected]>
--- drivers/staging/android/sync.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/android/sync.c +4 -4
@@ -92,14 +92,14 @@ static void sync_timeline_free(struct kref *kref)void sync_timeline_destroy (struct sync_timeline *obj) { obj->destroyed = true; +smp_wmb ();/* -* If this is not the last reference, signal any children -* that their parent is going away. +* signal any children that their parent is going away. */ +sync_timeline_signal (obj); -if (!kref_put (&obj->kref, sync_timeline_free)) -sync_timeline_signal (obj); +kref_put (&obj->kref, sync_timeline_free); }EXPORT_SYMBOL (sync_timeline_destroy);
Signature · 1 line
1.8.3.2
PATCH 7/16 staging: sync: Fix a race condition between release_obj and print_obj
In reply to John StultzFrom: Alistair Strachan <[email protected]>
Before this change, a timeline would only be removed from the timeline list *after* the sync driver had its release_obj() called. However, the driver's release_obj() may free resources needed by print_obj().
Although the timeline list is locked when print_obj() is called, it is not locked when release_obj() is called. If one CPU was in print_obj() when another was in release_obj(), the print_obj() may make unsafe accesses.
It is not actually necessary to hold the timeline list lock when calling release_obj() if the call is made after the timeline is unlinked from the list, since there is no possibility another thread could be in -- or enter -- print_obj() for that timeline.
This change moves the release_obj() call to after the timeline is unlinked, preventing the above race from occurring.
--- drivers/staging/android/sync.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/android/sync.c +3 -3
@@ -79,13 +79,13 @@ static void sync_timeline_free(struct kref *kref) container_of(kref, struct sync_timeline, kref);unsigned long flags; -if (obj->ops->release_obj) - obj->ops->release_obj (obj); -spin_lock_irqsave (&sync_timeline_list_lock, flags);list_del (&obj->sync_timeline_list);spin_unlock_irqrestore (&sync_timeline_list_lock, flags); +if (obj->ops->release_obj) + obj->ops->release_obj (obj); +kfree (obj); }
Signature · 1 line
1.8.3.2
PATCH 8/16 staging: ashmem: Avoid deadlock between read and mmap calls
In reply to John StultzFrom: Todd Poynor <[email protected]>
Avoid holding ashmem_mutex across code that can page fault. Page faults grab the mmap_sem for the process, which are also held by mmap calls prior to calling ashmem_mmap, which locks ashmem_mutex. The reversed order of locking between the two can deadlock.
The calls that can page fault are read() and the ASHMEM_SET_NAME and ASHMEM_GET_NAME ioctls. Move the code that accesses userspace pages outside the ashmem_mutex.
--- drivers/staging/android/ashmem.c | 45 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-)
drivers/staging/android/ashmem.c +26 -19
@@ -295,21 +295,29 @@ static ssize_t ashmem_read(struct file *file, char __user *buf,/* If size is not set, or set to 0, always return EOF. */ if (asma->size ==0 ) - goto out; + goto out_unlock;if (!asma->file) { ret = -EBADF ; - goto out; + goto out_unlock; } - ret = asma->file->f_op->read (asma->file, buf, len, pos); -if (ret <0 ) - goto out; +mutex_unlock (&ashmem_mutex); -/** Update backing file pos, since f_ops->read() doesn't */ - asma->file->f_pos = *pos; +/* +* asma and asma->file are used outside the lock here. We assume +* once asma->file is set it will never be changed, and will not +* be destroyed until all references to the file are dropped and +* ashmem_release is called. +*/ + ret = asma->file->f_op->read (asma->file, buf, len, pos); +if (ret >=0 ) { +/** Update backing file pos, since f_ops->read() doesn't */ + asma->file->f_pos = *pos; + } +return ret; -out: +out_unlock:mutex_unlock (&ashmem_mutex);return ret; }
@@ -498,6 +506,7 @@ out:static int set_name (struct ashmem_area *asma,void __user *name) { +int len;int ret =0 ;char local_name[ASHMEM_NAME_LEN ];
@@ -510,21 +519,19 @@ static int set_name(struct ashmem_area *asma, void __user *name)* variable that does not need protection and later copy the local * variable to the structure member with lock held. */ -if (copy_from_user (local_name, name,ASHMEM_NAME_LEN )) -return -EFAULT ; - + len =strncpy_from_user (local_name, name,ASHMEM_NAME_LEN ); +if (len <0 ) +return len; +if (len ==ASHMEM_NAME_LEN ) + local_name[ASHMEM_NAME_LEN -1 ] ='\0' ;mutex_lock (&ashmem_mutex);/* cannot change an existing mapping's name */ -if (unlikely (asma->file)) { +if (unlikely (asma->file)) ret = -EINVAL ; - goto out; - } -memcpy (asma->name +ASHMEM_NAME_PREFIX_LEN , - local_name,ASHMEM_NAME_LEN ); - asma->name[ASHMEM_FULL_NAME_LEN -1 ] ='\0' ; -out: -mutex_unlock (&ashmem_mutex); +else +strcpy (asma->name +ASHMEM_NAME_PREFIX_LEN , local_name); +mutex_unlock (&ashmem_mutex);return ret; }
Signature · 1 line
1.8.3.2
PATCH 9/16 staging: ion: Create separate heap and client debugfs directories
In reply to John StultzFrom: Mitchel Humpherys <[email protected]>
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.
--- drivers/staging/android/ion/ion.c | 57 +++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-)
drivers/staging/android/ion/ion.c +49 -8
@@ -59,6 +59,8 @@ struct ion_device { unsigned long arg);struct rb_root clients;struct dentry *debug_root; +struct dentry *heaps_debug_root; +struct dentry *clients_debug_root; };/**
@@ -763,8 +765,15 @@ struct ion_client *ion_client_create(struct ion_device *dev,snprintf (debug_name,64 ,"%u" , client->pid); client->debug_root =debugfs_create_file (debug_name,0664 , - dev->debug_root, client, - &debug_client_fops); + dev->clients_debug_root, + client, &debug_client_fops); +if (!client->debug_root) { +char buf[256 ], *path; + path =dentry_path (dev->clients_debug_root, buf,256 ); +pr_err ("Failed to create client debugfs at %s/%s\n" , + path, debug_name); + } +up_write (&dev->lock);return client;
@@ -1443,6 +1452,8 @@ DEFINE_SIMPLE_ATTRIBUTE(debug_shrink_fops, debug_shrink_get,void ion_device_add_heap (struct ion_device *dev,struct ion_heap *heap) { +struct dentry *debug_file; +if (!heap->ops->allocate || !heap->ops->free || !heap->ops->map_dma || !heap->ops->unmap_dma) pr_err("%s: can not add heap with invalid ops struct.\n",
@@ -1457,15 +1468,31 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)the list later attempt higher id numbers first */ plist_node_init (&heap->node, -heap->id);plist_add (&heap->node, &dev->heaps); -debugfs_create_file (heap->name,0664 , dev->debug_root, heap, - &debug_heap_fops); + debug_file =debugfs_create_file (heap->name,0664 , + dev->heaps_debug_root, heap, + &debug_heap_fops); + +if (!debug_file) { +char buf[256 ], *path; + path =dentry_path (dev->heaps_debug_root, buf,256 ); +pr_err ("Failed to create heap debugfs at %s/%s\n" , + path, heap->name); + } +#ifdef DEBUG_HEAP_SHRINKER if (heap->shrinker.shrink) {char debug_name[64 ];snprintf (debug_name,64 ,"%s_shrink" , heap->name); -debugfs_create_file (debug_name,0644 , dev->debug_root, heap, - &debug_shrink_fops); + debug_file =debugfs_create_file ( + debug_name,0644 , dev->heaps_debug_root, heap, + &debug_shrink_fops); +if (!debug_file) { +char buf[256 ], *path; + path =dentry_path (dev->heaps_debug_root, buf,256 ); +pr_err ("Failed to create heap shrinker debugfs at %s/%s\n" , + path, debug_name); + } }#endif up_write (&dev->lock);
@@ -1494,8 +1521,21 @@ struct ion_device *ion_device_create(long (*custom_ioctl) } idev->debug_root =debugfs_create_dir ("ion" ,NULL ); -if (!idev->debug_root) -pr_err ("ion: failed to create debug files.\n" ); +if (!idev->debug_root) { +pr_err ("ion: failed to create debugfs root directory.\n" ); + goto debugfs_done; + } + idev->heaps_debug_root =debugfs_create_dir ("heaps" , idev->debug_root); +if (!idev->heaps_debug_root) { +pr_err ("ion: failed to create debugfs heaps directory.\n" ); + goto debugfs_done; + } + idev->clients_debug_root =debugfs_create_dir ("clients" , + idev->debug_root); +if (!idev->clients_debug_root) +pr_err ("ion: failed to create debugfs clients directory.\n" ); + +debugfs_done: idev->custom_ioctl = custom_ioctl; idev->buffers =RB_ROOT ;
@@ -1509,6 +1549,7 @@ struct ion_device *ion_device_create(long (*custom_ioctl)void ion_device_destroy (struct ion_device *dev) {misc_deregister (&dev->dev); +debugfs_remove_recursive (dev->debug_root);/* XXX need to free the heaps and clients ? */ kfree (dev); }
Signature · 1 line
1.8.3.2
PATCH 10/16 staging: ion: Fix debugfs handling of multiple kernel clients
In reply to John StultzFrom: Laura Abbott <[email protected]>
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.
--- drivers/staging/android/ion/ion.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/android/ion/ion.c +5 -5
@@ -718,7 +718,6 @@ struct ion_client *ion_client_create(struct ion_device *dev,struct rb_node **p;struct rb_node *parent =NULL ;struct ion_client *entry; -char debug_name[64 ];pid_t pid;get_task_struct (current->group_leader);
@@ -763,15 +762,14 @@ struct ion_client *ion_client_create(struct ion_device *dev,rb_link_node (&client->node, parent, p);rb_insert_color (&client->node, &dev->clients); -snprintf (debug_name,64 ,"%u" , client->pid); - client->debug_root =debugfs_create_file (debug_name,0664 , + client->debug_root =debugfs_create_file (name,0664 , dev->clients_debug_root, client, &debug_client_fops);if (!client->debug_root) {char buf[256 ], *path; path =dentry_path (dev->clients_debug_root, buf,256 );pr_err ("Failed to create client debugfs at %s/%s\n" , - path, debug_name); + path, name); }up_write (&dev->lock);
@@ -1302,9 +1300,11 @@ static int ion_open(struct inode *inode, struct file *file)struct miscdevice *miscdev = file->private_data; struct ion_device *dev = container_of(miscdev, struct ion_device, dev);struct ion_client *client; +char debug_name[64 ];pr_debug ("%s: %d\n" , __func__, __LINE__); - client =ion_client_create (dev,"user" ); +snprintf (debug_name,64 ,"%u" ,task_pid_nr (current->group_leader)); + client =ion_client_create (dev, debug_name);if (IS_ERR (client))return PTR_ERR (client); file->private_data = client;
Signature · 1 line
1.8.3.2
PATCH 11/16 staging: ion: Store a copy of the client name on client creation
In reply to John StultzFrom: Mitchel Humpherys <[email protected]>
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.
--- drivers/staging/android/ion/ion.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/staging/android/ion/ion.c +13 -6
@@ -734,19 +734,18 @@ struct ion_client *ion_client_create(struct ion_device *dev,task_unlock (current->group_leader); client =kzalloc (sizeof (struct ion_client ),GFP_KERNEL ); -if (!client) { -if (task) -put_task_struct (current->group_leader); -return ERR_PTR (-ENOMEM ); - } +if (!client) + goto err_put_task_struct; client->dev = dev; client->handles =RB_ROOT ;idr_init (&client->idr);mutex_init (&client->lock); - client->name = name; client->task = task; client->pid = pid; + client->name =kstrdup (name,GFP_KERNEL ); +if (!client->name) + goto err_free_client;down_write (&dev->lock); p = &dev->clients.rb_node;
@@ -775,6 +774,13 @@ struct ion_client *ion_client_create(struct ion_device *dev,up_write (&dev->lock);return client; + +err_free_client: +kfree (client); +err_put_task_struct: +if (task) +put_task_struct (current->group_leader); +return ERR_PTR (-ENOMEM ); }EXPORT_SYMBOL (ion_client_create);
@@ -799,6 +805,7 @@ void ion_client_destroy(struct ion_client *client)debugfs_remove_recursive (client->debug_root);up_write (&dev->lock); +kfree (client->name);kfree (client); }EXPORT_SYMBOL (ion_client_destroy);
Signature · 1 line
1.8.3.2
PATCH 12/16 staging: ion: Make sure all clients are exposed in debugfs
In reply to John StultzFrom: Mitchel Humpherys <[email protected]>
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.
--- drivers/staging/android/ion/ion.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
drivers/staging/android/ion/ion.c +36 -2
@@ -71,6 +71,8 @@ struct ion_device {* @idr: an idr space for allocating handle ids * @lock: lock protecting the tree of handles * @name: used for debugging +* @display_name: used for debugging (unique version of @name) +* @display_serial: used for debugging (to make display_name unique) * @task: used for debugging * * A client represents a list of buffers this client may access.
@@ -84,6 +86,8 @@ struct ion_client {struct idr idr;struct mutex lock;const char *name; +char *display_name; +int display_serial;struct task_struct *task;pid_t pid;struct dentry *debug_root;
@@ -710,6 +714,21 @@ static const struct file_operations debug_client_fops = { .release = single_release, }; +static int ion_get_client_serial (const struct rb_root *root, +const unsigned char *name) +{ +int serial =-1 ; +struct rb_node *node; +for (node =rb_first (root); node; node =rb_next (node)) { + struct ion_client *client = rb_entry(node, struct ion_client, + node); +if (strcmp (client->name, name)) +continue ; + serial =max (serial, client->display_serial); + } +return serial +1 ; +} +struct ion_client *ion_client_create (struct ion_device *dev,const char *name) {
@@ -720,6 +739,11 @@ struct ion_client *ion_client_create(struct ion_device *dev,struct ion_client *entry;pid_t pid; +if (!name) { +pr_err ("%s: Name cannot be null\n" , __func__); +return ERR_PTR (-EINVAL ); + } +get_task_struct (current->group_leader);task_lock (current->group_leader); pid =task_pid_nr (current->group_leader);
@@ -748,6 +772,13 @@ struct ion_client *ion_client_create(struct ion_device *dev, goto err_free_client;down_write (&dev->lock); + client->display_serial =ion_get_client_serial (&dev->clients, name); + client->display_name =kasprintf ( +GFP_KERNEL ,"%s-%d" , name, client->display_serial); +if (!client->display_name) { +up_write (&dev->lock); + goto err_free_client_name; + } p = &dev->clients.rb_node;while (*p) { parent = *p;
@@ -761,20 +792,22 @@ struct ion_client *ion_client_create(struct ion_device *dev,rb_link_node (&client->node, parent, p);rb_insert_color (&client->node, &dev->clients); - client->debug_root =debugfs_create_file (name,0664 , + client->debug_root =debugfs_create_file (client->display_name,0664 , dev->clients_debug_root, client, &debug_client_fops);if (!client->debug_root) {char buf[256 ], *path; path =dentry_path (dev->clients_debug_root, buf,256 );pr_err ("Failed to create client debugfs at %s/%s\n" , - path, name); + path, client->display_name); }up_write (&dev->lock);return client; +err_free_client_name: +kfree (client->name); err_free_client:kfree (client); err_put_task_struct:
@@ -805,6 +838,7 @@ void ion_client_destroy(struct ion_client *client)debugfs_remove_recursive (client->debug_root);up_write (&dev->lock); +kfree (client->display_name);kfree (client->name);kfree (client); }
Signature · 1 line
1.8.3.2
PATCH 13/16 staging: ion: Fix overflow and list bugs in system heap
In reply to John StultzFrom: Colin Cross <[email protected]>
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.
--- drivers/staging/android/ion/ion_system_heap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/staging/android/ion/ion_system_heap.c +5 -1
@@ -124,6 +124,7 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, info->page = page; info->order = orders[i]; +INIT_LIST_HEAD (&info->list);return info; }kfree (info);
@@ -145,12 +146,15 @@ static int ion_system_heap_allocate(struct ion_heap *heap,struct list_head pages;struct page_info *info, *tmp_info;int i =0 ; -long size_remaining =PAGE_ALIGN (size); +unsigned long size_remaining =PAGE_ALIGN (size);unsigned int max_order = orders[0 ];if (align >PAGE_SIZE )return -EINVAL ; +if (size /PAGE_SIZE > totalram_pages /2 ) +return -ENOMEM ; +INIT_LIST_HEAD (&pages);while (size_remaining >0 ) { info = alloc_largest_available(sys_heap, buffer, size_remaining,
Signature · 1 line
1.8.3.2
PATCH 14/16 staging: ion: Fix ION_IOC_FREE compat ioctl
In reply to John StultzFrom: Laura Abbott <[email protected]>
The compat ioctl for ION_IOC_FREE currently passes allocation data instead of the free data. Correct this.
--- drivers/staging/android/ion/compat_ion.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/staging/android/ion/compat_ion.c +22 -4
@@ -35,9 +35,14 @@ struct compat_ion_custom_data {compat_ulong_t arg; }; +struct compat_ion_handle_data { +compat_int_t handle; +}; +#define COMPAT_ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ struct compat_ion_allocation_data) -#define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) +#define COMPAT_ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, \ + struct compat_ion_handle_data)#define COMPAT_ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, \ struct compat_ion_custom_data)
@@ -64,6 +69,19 @@ static int compat_get_ion_allocation_data(return err; } +static int compat_get_ion_handle_data ( +struct compat_ion_handle_data __user *data32, +struct ion_handle_data __user *data) +{ +compat_int_t i; +int err; + + err =get_user (i, &data32->handle); + err |=put_user (i, &data->handle); + +return err; +} +static int compat_put_ion_allocation_data (struct compat_ion_allocation_data __user *data32,struct ion_allocation_data __user *data)
@@ -132,8 +150,8 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) }case COMPAT_ION_IOC_FREE : { -struct compat_ion_allocation_data __user *data32; -struct ion_allocation_data __user *data; +struct compat_ion_handle_data __user *data32; +struct ion_handle_data __user *data;int err; data32 =compat_ptr (arg);
@@ -141,7 +159,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (data ==NULL )return -EFAULT ; - err =compat_get_ion_allocation_data (data32, data); + err =compat_get_ion_handle_data (data32, data);if (err)return err;
Signature · 1 line
1.8.3.2
PATCH 15/16 staging: ion: Move shrinker out of heaps
In reply to John StultzFrom: Colin Cross <[email protected]>
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.
[jstultz: Resolved big conflicts with the shrinker api change. Also minor commit subject tweak.]
--- drivers/staging/android/ion/ion.c | 3 + drivers/staging/android/ion/ion_heap.c | 50 +++++++++++++++++ drivers/staging/android/ion/ion_page_pool.c | 8 +-- drivers/staging/android/ion/ion_priv.h | 21 ++++--- drivers/staging/android/ion/ion_system_heap.c | 80 ++++++--------------------- 5 files changed, 85 insertions(+), 77 deletions(-)
drivers/staging/android/ion/ion.c +3 -0
@@ -1503,6 +1503,9 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)if (heap->flags &ION_HEAP_FLAG_DEFER_FREE )ion_heap_init_deferred_free (heap); +if ((heap->flags &ION_HEAP_FLAG_DEFER_FREE ) || heap->ops->shrink) +ion_heap_init_shrinker (heap); + heap->dev = dev;down_write (&dev->lock);/* use negative heap->id to reverse the priority -- when traversing
drivers/staging/android/ion/ion_heap.c +50 -0
56 lines not on this page · raw message
drivers/staging/android/ion/ion_page_pool.c +3 -5
@@ -130,8 +130,7 @@ static int ion_page_pool_total(struct ion_page_pool *pool, bool high)int ion_page_pool_shrink (struct ion_page_pool *pool,gfp_t gfp_mask,int nr_to_scan) { -int nr_freed =0 ; -int i; +int freed;bool high; high = !!(gfp_mask & __GFP_HIGHMEM);
@@ -139,7 +138,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,if (nr_to_scan ==0 )return ion_page_pool_total (pool, high); -for (i =0 ; i < nr_to_scan; i++) { +for (freed =0 ; freed < nr_to_scan; freed++) {struct page *page;mutex_lock (&pool->mutex);
@@ -153,10 +152,9 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, }mutex_unlock (&pool->mutex);ion_page_pool_free_pages (pool, page); - nr_freed += (1 << pool->order); } -return nr_freed; +return freed; }struct ion_page_pool *ion_page_pool_create (gfp_t gfp_mask,unsigned int order)
drivers/staging/android/ion/ion_priv.h +12 -9
@@ -113,6 +113,7 @@ struct ion_heap_ops {void (*unmap_kernel) (struct ion_heap *heap,struct ion_buffer *buffer);int (*map_user) (struct ion_heap *mapper,struct ion_buffer *buffer,struct vm_area_struct *vma); +int (*shrink)(struct ion_heap *heap,gfp_t gfp_mask,int nr_to_scan); };/**
@@ -131,10 +132,7 @@ struct ion_heap_ops {* allocating. These are specified by platform data and * MUST be unique * @name: used for debugging -* @shrinker: a shrinker for the heap, if the heap caches system -* memory, it must define a shrinker to return it on low -* memory conditions, this includes system memory cached -* in the deferred free lists for heaps that support it +* @shrinker: a shrinker for the heap * @free_list: free list head if deferred free is used * @free_list_size size of the deferred free list in bytes * @lock: protects the free list
@@ -218,6 +216,16 @@ int ion_heap_buffer_zero(struct ion_buffer *buffer);int ion_heap_pages_zero (struct page *page,size_t size,pgprot_t pgprot);/** +* ion_heap_init_shrinker +* @heap: the heap +* +* If a heap sets the ION_HEAP_FLAG_DEFER_FREE flag or defines the shrink op +* this function will be called to setup a shrinker to shrink the freelists +* and call the heap's shrink op. +*/ +void ion_heap_init_shrinker (struct ion_heap *heap); + +/** * ion_heap_init_deferred_free -- initialize deferred free functionality * @heap: the heap *
@@ -304,13 +312,8 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr,* @low_count: number of lowmem items in the pool * @high_items: list of highmem items * @low_items: list of lowmem items -* @shrinker: a shrinker for the items * @mutex: lock protecting this struct and especially the count * item list -* @alloc: function to be used to allocate pageory when the pool -* is empty -* @free: function to be used to free pageory back to the system -* when the shrinker fires * @gfp_mask: gfp_mask to use from alloc * @order: order of pages in the pool * @list: plist node for list of pools
drivers/staging/android/ion/ion_system_heap.c +17 -63
103 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH 16/16 staging: ion: Add private buffer flag to skip page pooling on free
In reply to John StultzFrom: Mitchel Humpherys <[email protected]>
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.
--- drivers/staging/android/ion/ion_heap.c | 19 ++++++++++-- drivers/staging/android/ion/ion_priv.h | 42 ++++++++++++++++++++++++++- drivers/staging/android/ion/ion_system_heap.c | 4 +-- 3 files changed, 59 insertions(+), 6 deletions(-)
drivers/staging/android/ion/ion_heap.c +16 -3
@@ -178,7 +178,8 @@ size_t ion_heap_freelist_size(struct ion_heap *heap)return size; } -size_t ion_heap_freelist_drain (struct ion_heap *heap,size_t size) +static size_t _ion_heap_freelist_drain (struct ion_heap *heap,size_t size, +bool skip_pools) {struct ion_buffer *buffer;size_t total_drained =0 ;
@@ -197,6 +198,8 @@ size_t ion_heap_freelist_drain(struct ion_heap *heap, size_t size) list);list_del (&buffer->list); heap->free_list_size -= buffer->size; +if (skip_pools) + buffer->private_flags |=ION_PRIV_FLAG_SHRINKER_FREE ; total_drained += buffer->size;spin_unlock (&heap->free_lock);ion_buffer_destroy (buffer);
@@ -207,6 +210,16 @@ size_t ion_heap_freelist_drain(struct ion_heap *heap, size_t size)return total_drained; } +size_t ion_heap_freelist_drain (struct ion_heap *heap,size_t size) +{ +return _ion_heap_freelist_drain (heap, size, false); +} + +size_t ion_heap_freelist_shrink (struct ion_heap *heap,size_t size) +{ +return _ion_heap_freelist_drain (heap, size, true); +} +static int ion_heap_deferred_free (void *data) {struct ion_heap *heap = data;
@@ -278,10 +291,10 @@ static unsigned long ion_heap_shrink_scan(struct shrinker *shrinker,/* * shrink the free list first, no point in zeroing the memory if we're -* just going to reclaim it +* just going to reclaim it. Also, skip any possible page pooling. */ if (heap->flags &ION_HEAP_FLAG_DEFER_FREE ) - freed =ion_heap_freelist_drain (heap, to_scan *PAGE_SIZE ) / + freed =ion_heap_freelist_shrink (heap, to_scan *PAGE_SIZE ) /PAGE_SIZE ; to_scan -= freed;
drivers/staging/android/ion/ion_priv.h +41 -1
72 lines not on this page · raw message
drivers/staging/android/ion/ion_system_heap.c +2 -2
@@ -90,7 +90,7 @@ static void free_buffer_page(struct ion_system_heap *heap, {bool cached =ion_buffer_cached (buffer); -if (!cached) { +if (!cached && !(buffer->private_flags &ION_PRIV_FLAG_SHRINKER_FREE )) {struct ion_page_pool *pool = heap->pools[order_to_index (order)];ion_page_pool_free (pool, page); }else {
@@ -209,7 +209,7 @@ static void ion_system_heap_free(struct ion_buffer *buffer)/* uncached pages come from the page pools, zero them before returning for security purposes (other allocations are zerod at alloc time */ -if (!cached) +if (!cached && !(buffer->private_flags &ION_PRIV_FLAG_SHRINKER_FREE ))ion_heap_buffer_zero (buffer);for_each_sg (table->sgl, sg, table->nents, i)
Signature · 1 line
1.8.3.2
Greg KH
maintainerQuoted 5 lines · John Stultz
I recently went through the AOSP common.git android/3.10 tree to try to pull fixes that haven't been submitted upstream. I've cherry picked those patches and wanted to submit them here for review, and for hopeful inclusion into staging for 3.15.
Quoted 8 lines
In most cases the patches cherry-picked right over. In a few cases, there were collisions due to trivial changes and cleanups like spelling fixes. However, the "ion: Move shrinker out of heaps" patch required more complicated merge, due to the shrinker api change upstream in 3.12. Things build and appear to work, but I'd appreciate extra review there.
Anyway, please let me know if there's any feedback or suggestions.
As this series is ordered, I can't take any of them for 3.14-final (patch 1 is a cleanup patch, not for 3.14.)
Care to make 2 series, one for things you feel should be in 3.14 (i.e. bugfixes), and the other for what can wait for 3.15 (i.e. uapi header file stuff)?
thanks,
greg k-h
Quoted 13 lines · Greg KH
Quoted 12 lines · John Stultz
I recently went through the AOSP common.git android/3.10 tree to try to pull fixes that haven't been submitted upstream. I've cherry picked those patches and wanted to submit them here for review, and for hopeful inclusion into staging for 3.15.
In most cases the patches cherry-picked right over. In a few cases, there were collisions due to trivial changes and cleanups like spelling fixes. However, the "ion: Move shrinker out of heaps" patch required more complicated merge, due to the shrinker api change upstream in 3.12. Things build and appear to work, but I'd appreciate extra review there.
Quoted 3 lines
Quoted 1 line
Anyway, please let me know if there's any feedback or suggestions.
As this series is ordered, I can't take any of them for 3.14-final (patch 1 is a cleanup patch, not for 3.14.)
Right, I actually wasn't shooting for 3.14 at all with these.
Quoted 3 lines
Care to make 2 series, one for things you feel should be in 3.14 (i.e. bugfixes), and the other for what can wait for 3.15 (i.e. uapi header file stuff)?
Yea, I'll see if I can split them up.
thanks for the feedback!
-john