Skip to content

Commit 06220d7

Browse files
rnavmpe
authored andcommitted
powerpc/pseries: Introduce rwlock to gatekeep DTLB usage
Since we would be introducing a new user of the DTL buffer in a subsequent patch, we need a way to gatekeep use of the DTL buffer. The current debugfs interface for DTL allows registering and opening cpu-specific DTL buffers. Cpu specific files are exposed under debugfs 'powerpc/dtl/' node, and changing 'dtl_event_mask' in the same directory enables controlling the event mask used when registering DTL buffer for a particular cpu. Subsequently, we will be introducing a user of the DTL buffers that registers access to the DTL buffers across all cpus with the same event mask. To ensure these two users do not step on each other, we introduce a rwlock to gatekeep DTL buffer access. This fits the requirement of the current debugfs interface wanting to allow multiple independent cpu-specific users (read lock), and the subsequent user wanting exclusive access (write lock). Suggested-by: Michael Ellerman <[email protected]> Signed-off-by: Naveen N. Rao <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 1c85a2a commit 06220d7

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

arch/powerpc/include/asm/lppaca.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
#include <linux/cache.h>
3434
#include <linux/threads.h>
35+
#include <linux/spinlock_types.h>
3536
#include <asm/types.h>
3637
#include <asm/mmu.h>
3738
#include <asm/firmware.h>
@@ -166,6 +167,7 @@ struct dtl_entry {
166167
#define DTL_LOG_ALL (DTL_LOG_CEDE | DTL_LOG_PREEMPT | DTL_LOG_FAULT)
167168

168169
extern struct kmem_cache *dtl_cache;
170+
extern rwlock_t dtl_access_lock;
169171

170172
/*
171173
* When CONFIG_VIRT_CPU_ACCOUNTING_NATIVE = y, the cpu accounting code controls

arch/powerpc/platforms/pseries/dtl.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,16 @@ static int dtl_enable(struct dtl *dtl)
193193
if (dtl->buf)
194194
return -EBUSY;
195195

196+
/* ensure there are no other conflicting dtl users */
197+
if (!read_trylock(&dtl_access_lock))
198+
return -EBUSY;
199+
196200
n_entries = dtl_buf_entries;
197201
buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL, cpu_to_node(dtl->cpu));
198202
if (!buf) {
199203
printk(KERN_WARNING "%s: buffer alloc failed for cpu %d\n",
200204
__func__, dtl->cpu);
205+
read_unlock(&dtl_access_lock);
201206
return -ENOMEM;
202207
}
203208

@@ -214,8 +219,11 @@ static int dtl_enable(struct dtl *dtl)
214219
}
215220
spin_unlock(&dtl->lock);
216221

217-
if (rc)
222+
if (rc) {
223+
read_unlock(&dtl_access_lock);
218224
kmem_cache_free(dtl_cache, buf);
225+
}
226+
219227
return rc;
220228
}
221229

@@ -227,6 +235,7 @@ static void dtl_disable(struct dtl *dtl)
227235
dtl->buf = NULL;
228236
dtl->buf_entries = 0;
229237
spin_unlock(&dtl->lock);
238+
read_unlock(&dtl_access_lock);
230239
}
231240

232241
/* file interface */

arch/powerpc/platforms/pseries/lpar.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ void register_dtl_buffer(int cpu)
113113
}
114114
}
115115

116+
#ifdef CONFIG_PPC_SPLPAR
117+
DEFINE_RWLOCK(dtl_access_lock);
118+
#endif /* CONFIG_PPC_SPLPAR */
119+
116120
void vpa_init(int cpu)
117121
{
118122
int hwcpu = get_hard_smp_processor_id(cpu);

0 commit comments

Comments
 (0)