Skip to content

Commit 133a58c

Browse files
committed
Pull sn2-reduce-kmalloc-wrap into release branch
2 parents dc5cdd8 + 7aa6ba4 commit 133a58c

4 files changed

Lines changed: 85 additions & 68 deletions

File tree

‎arch/ia64/sn/kernel/xpc_channel.c‎

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,38 @@
2121
#include <linux/sched.h>
2222
#include <linux/cache.h>
2323
#include <linux/interrupt.h>
24-
#include <linux/slab.h>
2524
#include <linux/mutex.h>
2625
#include <linux/completion.h>
2726
#include <asm/sn/bte.h>
2827
#include <asm/sn/sn_sal.h>
2928
#include <asm/sn/xpc.h>
3029

3130

31+
/*
32+
* Guarantee that the kzalloc'd memory is cacheline aligned.
33+
*/
34+
static void *
35+
xpc_kzalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
36+
{
37+
/* see if kzalloc will give us cachline aligned memory by default */
38+
*base = kzalloc(size, flags);
39+
if (*base == NULL) {
40+
return NULL;
41+
}
42+
if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
43+
return *base;
44+
}
45+
kfree(*base);
46+
47+
/* nope, we'll have to do it ourselves */
48+
*base = kzalloc(size + L1_CACHE_BYTES, flags);
49+
if (*base == NULL) {
50+
return NULL;
51+
}
52+
return (void *) L1_CACHE_ALIGN((u64) *base);
53+
}
54+
55+
3256
/*
3357
* Set up the initial values for the XPartition Communication channels.
3458
*/
@@ -93,20 +117,19 @@ xpc_setup_infrastructure(struct xpc_partition *part)
93117
* Allocate all of the channel structures as a contiguous chunk of
94118
* memory.
95119
*/
96-
part->channels = kmalloc(sizeof(struct xpc_channel) * XPC_NCHANNELS,
120+
part->channels = kzalloc(sizeof(struct xpc_channel) * XPC_NCHANNELS,
97121
GFP_KERNEL);
98122
if (part->channels == NULL) {
99123
dev_err(xpc_chan, "can't get memory for channels\n");
100124
return xpcNoMemory;
101125
}
102-
memset(part->channels, 0, sizeof(struct xpc_channel) * XPC_NCHANNELS);
103126

104127
part->nchannels = XPC_NCHANNELS;
105128

106129

107130
/* allocate all the required GET/PUT values */
108131

109-
part->local_GPs = xpc_kmalloc_cacheline_aligned(XPC_GP_SIZE,
132+
part->local_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE,
110133
GFP_KERNEL, &part->local_GPs_base);
111134
if (part->local_GPs == NULL) {
112135
kfree(part->channels);
@@ -115,55 +138,51 @@ xpc_setup_infrastructure(struct xpc_partition *part)
115138
"values\n");
116139
return xpcNoMemory;
117140
}
118-
memset(part->local_GPs, 0, XPC_GP_SIZE);
119141

120-
part->remote_GPs = xpc_kmalloc_cacheline_aligned(XPC_GP_SIZE,
142+
part->remote_GPs = xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE,
121143
GFP_KERNEL, &part->remote_GPs_base);
122144
if (part->remote_GPs == NULL) {
123-
kfree(part->channels);
124-
part->channels = NULL;
125-
kfree(part->local_GPs_base);
126-
part->local_GPs = NULL;
127145
dev_err(xpc_chan, "can't get memory for remote get/put "
128146
"values\n");
147+
kfree(part->local_GPs_base);
148+
part->local_GPs = NULL;
149+
kfree(part->channels);
150+
part->channels = NULL;
129151
return xpcNoMemory;
130152
}
131-
memset(part->remote_GPs, 0, XPC_GP_SIZE);
132153

133154

134155
/* allocate all the required open and close args */
135156

136-
part->local_openclose_args = xpc_kmalloc_cacheline_aligned(
157+
part->local_openclose_args = xpc_kzalloc_cacheline_aligned(
137158
XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL,
138159
&part->local_openclose_args_base);
139160
if (part->local_openclose_args == NULL) {
140-
kfree(part->channels);
141-
part->channels = NULL;
142-
kfree(part->local_GPs_base);
143-
part->local_GPs = NULL;
161+
dev_err(xpc_chan, "can't get memory for local connect args\n");
144162
kfree(part->remote_GPs_base);
145163
part->remote_GPs = NULL;
146-
dev_err(xpc_chan, "can't get memory for local connect args\n");
164+
kfree(part->local_GPs_base);
165+
part->local_GPs = NULL;
166+
kfree(part->channels);
167+
part->channels = NULL;
147168
return xpcNoMemory;
148169
}
149-
memset(part->local_openclose_args, 0, XPC_OPENCLOSE_ARGS_SIZE);
150170

151-
part->remote_openclose_args = xpc_kmalloc_cacheline_aligned(
171+
part->remote_openclose_args = xpc_kzalloc_cacheline_aligned(
152172
XPC_OPENCLOSE_ARGS_SIZE, GFP_KERNEL,
153173
&part->remote_openclose_args_base);
154174
if (part->remote_openclose_args == NULL) {
155-
kfree(part->channels);
156-
part->channels = NULL;
157-
kfree(part->local_GPs_base);
158-
part->local_GPs = NULL;
159-
kfree(part->remote_GPs_base);
160-
part->remote_GPs = NULL;
175+
dev_err(xpc_chan, "can't get memory for remote connect args\n");
161176
kfree(part->local_openclose_args_base);
162177
part->local_openclose_args = NULL;
163-
dev_err(xpc_chan, "can't get memory for remote connect args\n");
178+
kfree(part->remote_GPs_base);
179+
part->remote_GPs = NULL;
180+
kfree(part->local_GPs_base);
181+
part->local_GPs = NULL;
182+
kfree(part->channels);
183+
part->channels = NULL;
164184
return xpcNoMemory;
165185
}
166-
memset(part->remote_openclose_args, 0, XPC_OPENCLOSE_ARGS_SIZE);
167186

168187

169188
xpc_initialize_channels(part, partid);
@@ -186,18 +205,18 @@ xpc_setup_infrastructure(struct xpc_partition *part)
186205
ret = request_irq(SGI_XPC_NOTIFY, xpc_notify_IRQ_handler, SA_SHIRQ,
187206
part->IPI_owner, (void *) (u64) partid);
188207
if (ret != 0) {
189-
kfree(part->channels);
190-
part->channels = NULL;
191-
kfree(part->local_GPs_base);
192-
part->local_GPs = NULL;
193-
kfree(part->remote_GPs_base);
194-
part->remote_GPs = NULL;
195-
kfree(part->local_openclose_args_base);
196-
part->local_openclose_args = NULL;
197-
kfree(part->remote_openclose_args_base);
198-
part->remote_openclose_args = NULL;
199208
dev_err(xpc_chan, "can't register NOTIFY IRQ handler, "
200209
"errno=%d\n", -ret);
210+
kfree(part->remote_openclose_args_base);
211+
part->remote_openclose_args = NULL;
212+
kfree(part->local_openclose_args_base);
213+
part->local_openclose_args = NULL;
214+
kfree(part->remote_GPs_base);
215+
part->remote_GPs = NULL;
216+
kfree(part->local_GPs_base);
217+
part->local_GPs = NULL;
218+
kfree(part->channels);
219+
part->channels = NULL;
201220
return xpcLackOfResources;
202221
}
203222

@@ -446,22 +465,20 @@ xpc_allocate_local_msgqueue(struct xpc_channel *ch)
446465
for (nentries = ch->local_nentries; nentries > 0; nentries--) {
447466

448467
nbytes = nentries * ch->msg_size;
449-
ch->local_msgqueue = xpc_kmalloc_cacheline_aligned(nbytes,
468+
ch->local_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
450469
GFP_KERNEL,
451470
&ch->local_msgqueue_base);
452471
if (ch->local_msgqueue == NULL) {
453472
continue;
454473
}
455-
memset(ch->local_msgqueue, 0, nbytes);
456474

457475
nbytes = nentries * sizeof(struct xpc_notify);
458-
ch->notify_queue = kmalloc(nbytes, GFP_KERNEL);
476+
ch->notify_queue = kzalloc(nbytes, GFP_KERNEL);
459477
if (ch->notify_queue == NULL) {
460478
kfree(ch->local_msgqueue_base);
461479
ch->local_msgqueue = NULL;
462480
continue;
463481
}
464-
memset(ch->notify_queue, 0, nbytes);
465482

466483
spin_lock_irqsave(&ch->lock, irq_flags);
467484
if (nentries < ch->local_nentries) {
@@ -501,13 +518,12 @@ xpc_allocate_remote_msgqueue(struct xpc_channel *ch)
501518
for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
502519

503520
nbytes = nentries * ch->msg_size;
504-
ch->remote_msgqueue = xpc_kmalloc_cacheline_aligned(nbytes,
521+
ch->remote_msgqueue = xpc_kzalloc_cacheline_aligned(nbytes,
505522
GFP_KERNEL,
506523
&ch->remote_msgqueue_base);
507524
if (ch->remote_msgqueue == NULL) {
508525
continue;
509526
}
510-
memset(ch->remote_msgqueue, 0, nbytes);
511527

512528
spin_lock_irqsave(&ch->lock, irq_flags);
513529
if (nentries < ch->remote_nentries) {

‎arch/ia64/sn/kernel/xpc_main.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include <linux/syscalls.h>
5353
#include <linux/cache.h>
5454
#include <linux/interrupt.h>
55-
#include <linux/slab.h>
5655
#include <linux/delay.h>
5756
#include <linux/reboot.h>
5857
#include <linux/completion.h>

‎arch/ia64/sn/kernel/xpc_partition.c‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ char ____cacheline_aligned xpc_remote_copy_buffer[XPC_RP_HEADER_SIZE +
8080
XP_NASID_MASK_BYTES];
8181

8282

83+
/*
84+
* Guarantee that the kmalloc'd memory is cacheline aligned.
85+
*/
86+
static void *
87+
xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
88+
{
89+
/* see if kmalloc will give us cachline aligned memory by default */
90+
*base = kmalloc(size, flags);
91+
if (*base == NULL) {
92+
return NULL;
93+
}
94+
if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
95+
return *base;
96+
}
97+
kfree(*base);
98+
99+
/* nope, we'll have to do it ourselves */
100+
*base = kmalloc(size + L1_CACHE_BYTES, flags);
101+
if (*base == NULL) {
102+
return NULL;
103+
}
104+
return (void *) L1_CACHE_ALIGN((u64) *base);
105+
}
106+
107+
83108
/*
84109
* Given a nasid, get the physical address of the partition's reserved page
85110
* for that nasid. This function returns 0 on any error.
@@ -1038,13 +1063,12 @@ xpc_discovery(void)
10381063
remote_vars = (struct xpc_vars *) remote_rp;
10391064

10401065

1041-
discovered_nasids = kmalloc(sizeof(u64) * xp_nasid_mask_words,
1066+
discovered_nasids = kzalloc(sizeof(u64) * xp_nasid_mask_words,
10421067
GFP_KERNEL);
10431068
if (discovered_nasids == NULL) {
10441069
kfree(remote_rp_base);
10451070
return;
10461071
}
1047-
memset(discovered_nasids, 0, sizeof(u64) * xp_nasid_mask_words);
10481072

10491073
rp = (struct xpc_rsvd_page *) xpc_rsvd_page;
10501074

‎include/asm-ia64/sn/xpc.h‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,28 +1227,6 @@ xpc_map_bte_errors(bte_result_t error)
12271227

12281228

12291229

1230-
static inline void *
1231-
xpc_kmalloc_cacheline_aligned(size_t size, gfp_t flags, void **base)
1232-
{
1233-
/* see if kmalloc will give us cachline aligned memory by default */
1234-
*base = kmalloc(size, flags);
1235-
if (*base == NULL) {
1236-
return NULL;
1237-
}
1238-
if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
1239-
return *base;
1240-
}
1241-
kfree(*base);
1242-
1243-
/* nope, we'll have to do it ourselves */
1244-
*base = kmalloc(size + L1_CACHE_BYTES, flags);
1245-
if (*base == NULL) {
1246-
return NULL;
1247-
}
1248-
return (void *) L1_CACHE_ALIGN((u64) *base);
1249-
}
1250-
1251-
12521230
/*
12531231
* Check to see if there is any channel activity to/from the specified
12541232
* partition.

0 commit comments

Comments
 (0)