Skip to content

Commit bbf79d2

Browse files
suryasaimadhuIngo Molnar
authored andcommitted
x86/ldt: Rename ldt_struct::size to ::nr_entries
... because this is exactly what it is: the number of entries in the LDT. Calling it "size" is simply confusing and it is actually begging to be called "nr_entries" or somesuch, especially if you see constructs like: alloc_size = size * LDT_ENTRY_SIZE; since LDT_ENTRY_SIZE is the size of a single entry. There should be no functionality change resulting from this patch, as the before/after output from tools/testing/selftests/x86/ldt_gdt.c shows. Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Andy Lutomirski <luto@amacapital.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20170606173116.13977-1-bp@alien8.de [ Renamed 'n_entries' to 'nr_entries' ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5dd0b16 commit bbf79d2

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

arch/x86/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ static unsigned long get_segment_base(unsigned int segment)
23332333

23342334
/* IRQs are off, so this synchronizes with smp_store_release */
23352335
ldt = lockless_dereference(current->active_mm->context.ldt);
2336-
if (!ldt || idx > ldt->size)
2336+
if (!ldt || idx > ldt->nr_entries)
23372337
return 0;
23382338

23392339
desc = &ldt->entries[idx];

arch/x86/include/asm/mmu_context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct ldt_struct {
4747
* allocations, but it's not worth trying to optimize.
4848
*/
4949
struct desc_struct *entries;
50-
unsigned int size;
50+
unsigned int nr_entries;
5151
};
5252

5353
/*
@@ -87,7 +87,7 @@ static inline void load_mm_ldt(struct mm_struct *mm)
8787
*/
8888

8989
if (unlikely(ldt))
90-
set_ldt(ldt->entries, ldt->size);
90+
set_ldt(ldt->entries, ldt->nr_entries);
9191
else
9292
clear_LDT();
9393
#else

arch/x86/kernel/ldt.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ static void flush_ldt(void *__mm)
3131
return;
3232

3333
pc = &mm->context;
34-
set_ldt(pc->ldt->entries, pc->ldt->size);
34+
set_ldt(pc->ldt->entries, pc->ldt->nr_entries);
3535
}
3636

3737
/* The caller must call finalize_ldt_struct on the result. LDT starts zeroed. */
38-
static struct ldt_struct *alloc_ldt_struct(unsigned int size)
38+
static struct ldt_struct *alloc_ldt_struct(unsigned int num_entries)
3939
{
4040
struct ldt_struct *new_ldt;
4141
unsigned int alloc_size;
4242

43-
if (size > LDT_ENTRIES)
43+
if (num_entries > LDT_ENTRIES)
4444
return NULL;
4545

4646
new_ldt = kmalloc(sizeof(struct ldt_struct), GFP_KERNEL);
4747
if (!new_ldt)
4848
return NULL;
4949

5050
BUILD_BUG_ON(LDT_ENTRY_SIZE != sizeof(struct desc_struct));
51-
alloc_size = size * LDT_ENTRY_SIZE;
51+
alloc_size = num_entries * LDT_ENTRY_SIZE;
5252

5353
/*
5454
* Xen is very picky: it requires a page-aligned LDT that has no
@@ -66,14 +66,14 @@ static struct ldt_struct *alloc_ldt_struct(unsigned int size)
6666
return NULL;
6767
}
6868

69-
new_ldt->size = size;
69+
new_ldt->nr_entries = num_entries;
7070
return new_ldt;
7171
}
7272

7373
/* After calling this, the LDT is immutable. */
7474
static void finalize_ldt_struct(struct ldt_struct *ldt)
7575
{
76-
paravirt_alloc_ldt(ldt->entries, ldt->size);
76+
paravirt_alloc_ldt(ldt->entries, ldt->nr_entries);
7777
}
7878

7979
/* context.lock is held */
@@ -92,8 +92,8 @@ static void free_ldt_struct(struct ldt_struct *ldt)
9292
if (likely(!ldt))
9393
return;
9494

95-
paravirt_free_ldt(ldt->entries, ldt->size);
96-
if (ldt->size * LDT_ENTRY_SIZE > PAGE_SIZE)
95+
paravirt_free_ldt(ldt->entries, ldt->nr_entries);
96+
if (ldt->nr_entries * LDT_ENTRY_SIZE > PAGE_SIZE)
9797
vfree_atomic(ldt->entries);
9898
else
9999
free_page((unsigned long)ldt->entries);
@@ -123,14 +123,14 @@ int init_new_context_ldt(struct task_struct *tsk, struct mm_struct *mm)
123123
goto out_unlock;
124124
}
125125

126-
new_ldt = alloc_ldt_struct(old_mm->context.ldt->size);
126+
new_ldt = alloc_ldt_struct(old_mm->context.ldt->nr_entries);
127127
if (!new_ldt) {
128128
retval = -ENOMEM;
129129
goto out_unlock;
130130
}
131131

132132
memcpy(new_ldt->entries, old_mm->context.ldt->entries,
133-
new_ldt->size * LDT_ENTRY_SIZE);
133+
new_ldt->nr_entries * LDT_ENTRY_SIZE);
134134
finalize_ldt_struct(new_ldt);
135135

136136
mm->context.ldt = new_ldt;
@@ -153,9 +153,9 @@ void destroy_context_ldt(struct mm_struct *mm)
153153

154154
static int read_ldt(void __user *ptr, unsigned long bytecount)
155155
{
156-
int retval;
157-
unsigned long size;
158156
struct mm_struct *mm = current->mm;
157+
unsigned long entries_size;
158+
int retval;
159159

160160
mutex_lock(&mm->context.lock);
161161

@@ -167,18 +167,18 @@ static int read_ldt(void __user *ptr, unsigned long bytecount)
167167
if (bytecount > LDT_ENTRY_SIZE * LDT_ENTRIES)
168168
bytecount = LDT_ENTRY_SIZE * LDT_ENTRIES;
169169

170-
size = mm->context.ldt->size * LDT_ENTRY_SIZE;
171-
if (size > bytecount)
172-
size = bytecount;
170+
entries_size = mm->context.ldt->nr_entries * LDT_ENTRY_SIZE;
171+
if (entries_size > bytecount)
172+
entries_size = bytecount;
173173

174-
if (copy_to_user(ptr, mm->context.ldt->entries, size)) {
174+
if (copy_to_user(ptr, mm->context.ldt->entries, entries_size)) {
175175
retval = -EFAULT;
176176
goto out_unlock;
177177
}
178178

179-
if (size != bytecount) {
179+
if (entries_size != bytecount) {
180180
/* Zero-fill the rest and pretend we read bytecount bytes. */
181-
if (clear_user(ptr + size, bytecount - size)) {
181+
if (clear_user(ptr + entries_size, bytecount - entries_size)) {
182182
retval = -EFAULT;
183183
goto out_unlock;
184184
}
@@ -209,7 +209,7 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
209209
{
210210
struct mm_struct *mm = current->mm;
211211
struct ldt_struct *new_ldt, *old_ldt;
212-
unsigned int oldsize, newsize;
212+
unsigned int old_nr_entries, new_nr_entries;
213213
struct user_desc ldt_info;
214214
struct desc_struct ldt;
215215
int error;
@@ -248,17 +248,18 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
248248

249249
mutex_lock(&mm->context.lock);
250250

251-
old_ldt = mm->context.ldt;
252-
oldsize = old_ldt ? old_ldt->size : 0;
253-
newsize = max(ldt_info.entry_number + 1, oldsize);
251+
old_ldt = mm->context.ldt;
252+
old_nr_entries = old_ldt ? old_ldt->nr_entries : 0;
253+
new_nr_entries = max(ldt_info.entry_number + 1, old_nr_entries);
254254

255255
error = -ENOMEM;
256-
new_ldt = alloc_ldt_struct(newsize);
256+
new_ldt = alloc_ldt_struct(new_nr_entries);
257257
if (!new_ldt)
258258
goto out_unlock;
259259

260260
if (old_ldt)
261-
memcpy(new_ldt->entries, old_ldt->entries, oldsize * LDT_ENTRY_SIZE);
261+
memcpy(new_ldt->entries, old_ldt->entries, old_nr_entries * LDT_ENTRY_SIZE);
262+
262263
new_ldt->entries[ldt_info.entry_number] = ldt;
263264
finalize_ldt_struct(new_ldt);
264265

arch/x86/kernel/process_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void release_thread(struct task_struct *dead_task)
142142
pr_warn("WARNING: dead process %s still has LDT? <%p/%d>\n",
143143
dead_task->comm,
144144
dead_task->mm->context.ldt->entries,
145-
dead_task->mm->context.ldt->size);
145+
dead_task->mm->context.ldt->nr_entries);
146146
BUG();
147147
}
148148
#endif

arch/x86/kernel/step.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
3434

3535
mutex_lock(&child->mm->context.lock);
3636
if (unlikely(!child->mm->context.ldt ||
37-
seg >= child->mm->context.ldt->size))
37+
seg >= child->mm->context.ldt->nr_entries))
3838
addr = -1L; /* bogus selector, access would fault */
3939
else {
4040
desc = &child->mm->context.ldt->entries[seg];

arch/x86/math-emu/fpu_system.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static inline struct desc_struct FPU_get_ldt_descriptor(unsigned seg)
2727
#ifdef CONFIG_MODIFY_LDT_SYSCALL
2828
seg >>= 3;
2929
mutex_lock(&current->mm->context.lock);
30-
if (current->mm->context.ldt && seg < current->mm->context.ldt->size)
30+
if (current->mm->context.ldt && seg < current->mm->context.ldt->nr_entries)
3131
ret = current->mm->context.ldt->entries[seg];
3232
mutex_unlock(&current->mm->context.lock);
3333
#endif

0 commit comments

Comments
 (0)