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 ) {
0 commit comments