1 From e0412853d9f9e12fc7d8a3125cc3b4a62d19007d Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Mon, 12 May 2014 15:12:02 +0100
4 Subject: [PATCH 011/114] vchiq: Avoid high load when blocked and unkillable
6 vchiq: Include SIGSTOP and SIGCONT in list of signals not-masked by vchiq to allow gdb to work
8 .../interface/vchiq_arm/vchiq_2835_arm.c | 1 +
9 .../vc04_services/interface/vchiq_arm/vchiq_arm.c | 1 +
10 .../interface/vchiq_arm/vchiq_connected.c | 1 +
11 .../vc04_services/interface/vchiq_arm/vchiq_core.c | 1 +
12 .../interface/vchiq_arm/vchiq_kern_lib.c | 1 +
13 .../interface/vchiq_arm/vchiq_killable.h | 69 ++++++++++++++++++++++
14 .../vc04_services/interface/vchiq_arm/vchiq_util.c | 1 +
15 7 files changed, 75 insertions(+)
16 create mode 100644 drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
18 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
19 index b3bdaa2..7e7b09f 100644
20 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
21 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
23 #include "vchiq_arm.h"
24 #include "vchiq_2835.h"
25 #include "vchiq_connected.h"
26 +#include "vchiq_killable.h"
28 #define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
30 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
31 index 2596818..3e328ab 100644
32 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
33 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
35 #include "vchiq_ioctl.h"
36 #include "vchiq_arm.h"
37 #include "vchiq_debugfs.h"
38 +#include "vchiq_killable.h"
40 #define DEVICE_NAME "vchiq"
42 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
43 index 65f4b52..5efc62f 100644
44 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
45 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
48 #include "vchiq_connected.h"
49 #include "vchiq_core.h"
50 +#include "vchiq_killable.h"
51 #include <linux/module.h>
52 #include <linux/mutex.h>
54 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
55 index f962027..14a4155 100644
56 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
57 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
61 #include "vchiq_core.h"
62 +#include "vchiq_killable.h"
64 #define VCHIQ_SLOT_HANDLER_STACK 8192
66 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
67 index be9735f..5a4182e 100644
68 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
69 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
72 #include "vchiq_core.h"
73 #include "vchiq_arm.h"
74 +#include "vchiq_killable.h"
76 /* ---- Public Variables ------------------------------------------------- */
78 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
80 index 0000000..335446e
82 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
85 + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
87 + * Redistribution and use in source and binary forms, with or without
88 + * modification, are permitted provided that the following conditions
90 + * 1. Redistributions of source code must retain the above copyright
91 + * notice, this list of conditions, and the following disclaimer,
92 + * without modification.
93 + * 2. Redistributions in binary form must reproduce the above copyright
94 + * notice, this list of conditions and the following disclaimer in the
95 + * documentation and/or other materials provided with the distribution.
96 + * 3. The names of the above-listed copyright holders may not be used
97 + * to endorse or promote products derived from this software without
98 + * specific prior written permission.
100 + * ALTERNATIVELY, this software may be distributed under the terms of the
101 + * GNU General Public License ("GPL") version 2, as published by the Free
102 + * Software Foundation.
104 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
105 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
106 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
107 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
108 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
109 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
110 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
111 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
112 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
113 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
114 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
117 +#ifndef VCHIQ_KILLABLE_H
118 +#define VCHIQ_KILLABLE_H
120 +#include <linux/mutex.h>
121 +#include <linux/semaphore.h>
123 +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT) | sigmask(SIGTRAP) | sigmask(SIGSTOP) | sigmask(SIGCONT))
125 +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
127 + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
129 + sigset_t blocked, oldset;
130 + siginitsetinv(&blocked, SHUTDOWN_SIGS);
131 + sigprocmask(SIG_SETMASK, &blocked, &oldset);
132 + ret = down_interruptible(sem);
133 + sigprocmask(SIG_SETMASK, &oldset, NULL);
136 +#define down_interruptible down_interruptible_killable
139 +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
141 + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
143 + sigset_t blocked, oldset;
144 + siginitsetinv(&blocked, SHUTDOWN_SIGS);
145 + sigprocmask(SIG_SETMASK, &blocked, &oldset);
146 + ret = mutex_lock_interruptible(lock);
147 + sigprocmask(SIG_SETMASK, &oldset, NULL);
150 +#define mutex_lock_interruptible mutex_lock_interruptible_killable
153 diff --git a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
154 index c2eefef..05e7979 100644
155 --- a/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
156 +++ b/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
160 #include "vchiq_util.h"
161 +#include "vchiq_killable.h"
163 static inline int is_pow2(int i)