From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932865AbdLRHNa (ORCPT ); Mon, 18 Dec 2017 02:13:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:44992 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932837AbdLRHN0 (ORCPT ); Mon, 18 Dec 2017 02:13:26 -0500 From: NeilBrown To: Oleg Drokin , Andreas Dilger , James Simmons , Greg Kroah-Hartman Date: Mon, 18 Dec 2017 18:13:13 +1100 Cc: lkml , lustre Subject: Re: [lustre-devel] [PATCH 08/15] staging: lustre: Convert more LIBCFS_ALLOC allocation to direct GFP_KERNEL In-Reply-To: <151355799049.6200.16488920506903028598.stgit@noble> References: <151355781721.6200.2136335532722530242.stgit@noble> <151355799049.6200.16488920506903028598.stgit@noble> Message-ID: <87y3m0ld9y.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Sorry, it seems I mustn't have tested the file version of this patch. That "kvmalloc_node()" was clearly wrong. This version passes testing. Thanks, NeilBrown "git am" will ignore everything before this line: =2D----------------8<----------------- None of these need to be GFP_NOFS, so use GFP_KERNEL explicitly with kmalloc(), kvmalloc(), or kvmalloc_array(). Changing matching LIBCFS_FREE() to kfree() or kvfree() Signed-off-by: NeilBrown =2D-- .../lustre/lnet/libcfs/linux/linux-module.c | 4 +-- drivers/staging/lustre/lnet/libcfs/module.c | 9 +++--- drivers/staging/lustre/lnet/lnet/api-ni.c | 17 +++++------ drivers/staging/lustre/lnet/lnet/config.c | 34 +++++++++---------= ---- 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c b/driv= ers/staging/lustre/lnet/libcfs/linux/linux-module.c index b5746230ab31..ddf625669bff 100644 =2D-- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c +++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c @@ -146,7 +146,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_= pp, return -EINVAL; } =20 =2D LIBCFS_ALLOC(*hdr_pp, hdr.ioc_len); + *hdr_pp =3D kvmalloc(hdr.ioc_len, GFP_KERNEL); if (!*hdr_pp) return -ENOMEM; =20 @@ -164,7 +164,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_= pp, return 0; =20 free: =2D LIBCFS_FREE(*hdr_pp, hdr.ioc_len); + kvfree(*hdr_pp); return err; } =20 diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/= lustre/lnet/libcfs/module.c index 4ead55920e79..1bd33497a7c0 100644 =2D-- a/drivers/staging/lustre/lnet/libcfs/module.c +++ b/drivers/staging/lustre/lnet/libcfs/module.c @@ -156,7 +156,7 @@ int libcfs_ioctl(unsigned long cmd, void __user *uparam) break; } } out: =2D LIBCFS_FREE(hdr, hdr->ioc_len); + kvfree(hdr); return err; } =20 @@ -302,7 +302,7 @@ static int __proc_cpt_table(void *data, int write, LASSERT(cfs_cpt_table); =20 while (1) { =2D LIBCFS_ALLOC(buf, len); + buf =3D kzalloc(len, GFP_KERNEL); if (!buf) return -ENOMEM; =20 @@ -311,7 +311,7 @@ static int __proc_cpt_table(void *data, int write, break; =20 if (rc =3D=3D -EFBIG) { =2D LIBCFS_FREE(buf, len); + kfree(buf); len <<=3D 1; continue; } @@ -325,8 +325,7 @@ static int __proc_cpt_table(void *data, int write, =20 rc =3D cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); out: =2D if (buf) =2D LIBCFS_FREE(buf, len); + kfree(buf); return rc; } =20 diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lu= stre/lnet/lnet/api-ni.c index e8f623190133..6a1fb0397604 100644 =2D-- a/drivers/staging/lustre/lnet/lnet/api-ni.c +++ b/drivers/staging/lustre/lnet/lnet/api-ni.c @@ -108,7 +108,8 @@ lnet_create_remote_nets_table(void) =20 LASSERT(!the_lnet.ln_remote_nets_hash); LASSERT(the_lnet.ln_remote_nets_hbits > 0); =2D LIBCFS_ALLOC(hash, LNET_REMOTE_NETS_HASH_SIZE * sizeof(*hash)); + hash =3D kvmalloc_array(LNET_REMOTE_NETS_HASH_SIZE, sizeof(*hash), + GFP_KERNEL); if (!hash) { CERROR("Failed to create remote nets hash table\n"); return -ENOMEM; @@ -131,9 +132,7 @@ lnet_destroy_remote_nets_table(void) for (i =3D 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) LASSERT(list_empty(&the_lnet.ln_remote_nets_hash[i])); =20 =2D LIBCFS_FREE(the_lnet.ln_remote_nets_hash, =2D LNET_REMOTE_NETS_HASH_SIZE * =2D sizeof(the_lnet.ln_remote_nets_hash[0])); + kvfree(the_lnet.ln_remote_nets_hash); the_lnet.ln_remote_nets_hash =3D NULL; } =20 @@ -831,7 +830,7 @@ lnet_ping_info_create(int num_ni) unsigned int infosz; =20 infosz =3D offsetof(struct lnet_ping_info, pi_ni[num_ni]); =2D LIBCFS_ALLOC(ping_info, infosz); + ping_info =3D kvzalloc(infosz, GFP_KERNEL); if (!ping_info) { CERROR("Can't allocate ping info[%d]\n", num_ni); return NULL; @@ -864,9 +863,7 @@ lnet_get_ni_count(void) static inline void lnet_ping_info_free(struct lnet_ping_info *pinfo) { =2D LIBCFS_FREE(pinfo, =2D offsetof(struct lnet_ping_info, =2D pi_ni[pinfo->pi_nnis])); + kvfree(pinfo); } =20 static void @@ -2160,7 +2157,7 @@ static int lnet_ping(struct lnet_process_id id, int t= imeout_ms, if (id.pid =3D=3D LNET_PID_ANY) id.pid =3D LNET_PID_LUSTRE; =20 =2D LIBCFS_ALLOC(info, infosz); + info =3D kzalloc(infosz, GFP_KERNEL); if (!info) return -ENOMEM; =20 @@ -2310,6 +2307,6 @@ static int lnet_ping(struct lnet_process_id id, int t= imeout_ms, LASSERT(!rc2); =20 out_0: =2D LIBCFS_FREE(info, infosz); + kfree(info); return rc; } diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lu= stre/lnet/lnet/config.c index 66a222e5220b..fd53c74766a7 100644 =2D-- a/drivers/staging/lustre/lnet/lnet/config.c +++ b/drivers/staging/lustre/lnet/lnet/config.c @@ -109,10 +109,8 @@ lnet_ni_free(struct lnet_ni *ni) if (ni->ni_lnd_tunables) kfree(ni->ni_lnd_tunables); =20 =2D for (i =3D 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) { =2D LIBCFS_FREE(ni->ni_interfaces[i], =2D strlen(ni->ni_interfaces[i]) + 1); =2D } + for (i =3D 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) + kfree(ni->ni_interfaces[i]); =20 /* release reference to net namespace */ if (ni->ni_net_ns) @@ -198,7 +196,6 @@ int lnet_parse_networks(struct list_head *nilist, char *networks) { struct cfs_expr_list *el =3D NULL; =2D int tokensize; char *tokens; char *str; char *tmp; @@ -219,15 +216,12 @@ lnet_parse_networks(struct list_head *nilist, char *n= etworks) return -EINVAL; } =20 =2D tokensize =3D strlen(networks) + 1; =2D =2D LIBCFS_ALLOC(tokens, tokensize); + tokens =3D kstrdup(networks, GFP_KERNEL); if (!tokens) { CERROR("Can't allocate net tokens\n"); return -ENOMEM; } =20 =2D memcpy(tokens, networks, tokensize); tmp =3D tokens; str =3D tokens; =20 @@ -349,14 +343,11 @@ lnet_parse_networks(struct list_head *nilist, char *n= etworks) * The newly allocated ni_interfaces[] can be * freed when freeing the NI */ =2D LIBCFS_ALLOC(ni->ni_interfaces[niface], =2D strlen(iface) + 1); + ni->ni_interfaces[niface] =3D kstrdup(iface, GFP_KERNEL); if (!ni->ni_interfaces[niface]) { CERROR("Can't allocate net interface name\n"); goto failed; } =2D strncpy(ni->ni_interfaces[niface], iface, =2D strlen(iface)); niface++; iface =3D comma; } while (iface); @@ -384,7 +375,7 @@ lnet_parse_networks(struct list_head *nilist, char *net= works) list_for_each(temp_node, nilist) nnets++; =20 =2D LIBCFS_FREE(tokens, tokensize); + kfree(tokens); return nnets; =20 failed_syntax: @@ -400,7 +391,7 @@ lnet_parse_networks(struct list_head *nilist, char *net= works) if (el) cfs_expr_list_free(el); =20 =2D LIBCFS_FREE(tokens, tokensize); + kfree(tokens); =20 return -EINVAL; } @@ -424,7 +415,7 @@ lnet_new_text_buf(int str_len) return NULL; } =20 =2D LIBCFS_ALLOC(ltb, nob); + ltb =3D kzalloc(nob, GFP_KERNEL); if (!ltb) return NULL; =20 @@ -438,7 +429,7 @@ static void lnet_free_text_buf(struct lnet_text_buf *ltb) { lnet_tbnob -=3D ltb->ltb_size; =2D LIBCFS_FREE(ltb, ltb->ltb_size); + kfree(ltb); } =20 static void @@ -1156,7 +1147,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) if (nif <=3D 0) return nif; =20 =2D LIBCFS_ALLOC(ipaddrs, nif * sizeof(*ipaddrs)); + ipaddrs =3D kzalloc(nif * sizeof(*ipaddrs), GFP_KERNEL); if (!ipaddrs) { CERROR("Can't allocate ipaddrs[%d]\n", nif); lnet_ipif_free_enumeration(ifnames, nif); @@ -1189,7 +1180,8 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) *ipaddrsp =3D ipaddrs; } else { if (nip > 0) { =2D LIBCFS_ALLOC(ipaddrs2, nip * sizeof(*ipaddrs2)); + ipaddrs2 =3D kzalloc(nip * sizeof(*ipaddrs2), + GFP_KERNEL); if (!ipaddrs2) { CERROR("Can't allocate ipaddrs[%d]\n", nip); nip =3D -ENOMEM; @@ -1200,7 +1192,7 @@ lnet_ipaddr_enumerate(__u32 **ipaddrsp) rc =3D nip; } } =2D LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); + kfree(ipaddrs); } return nip; } @@ -1226,7 +1218,7 @@ lnet_parse_ip2nets(char **networksp, char *ip2nets) } =20 rc =3D lnet_match_networks(networksp, ip2nets, ipaddrs, nip); =2D LIBCFS_FREE(ipaddrs, nip * sizeof(*ipaddrs)); + kfree(ipaddrs); =20 if (rc < 0) { LCONSOLE_ERROR_MSG(0x119, "Error %d parsing ip2nets\n", rc); =2D-=20 2.14.0.rc0.dirty --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlo3aosACgkQOeye3VZi gbnNOw//ecHky5rrCAmHhmCDjcfyi9EOmAZZf/HGaz70bucjTgKKeLNln19ZJ3Zv bzQ2juawoA29sN6dKwWYXMgVnTWOcjqkrwbPmq6ZcSRVMGDFLjbl5oYXs8iTjWhJ uKV1jwhTUDuUI332qnfbdtJRTGxsRJBjPNmcFutiQWHRIryek9g6t6SuzjsJ16i8 beykb6guIPNePI1jgCbEKiFykc51PxugAFHKNtwRKpac3tKiQFqmTcC3BRmEugNa 7rtWYDMBVcH7aAhjJHcNCuN4PM0j6Mp+DVgOv6A0L+SiE1buce9zQinrXrPfYSW6 EVogEWjJXs4+Hm9WCZXlxqKP8ip2ERwYcs44ck/TKlgPGT15x/Z2mKcBHVkRY3Tv xrofwtNl4WkSq5XvsRY9pSJoPWLrjqMsaPipR2yk47ESnUMU4mGvPS9Y8KCnZngY jZDpflXoJONi7/SP8GJX0qyFMz0DtCFuFawoadLaozX444JweRYe6S81xre02P/g 2nMA8llGbr6tnBrWBIQXKKBrCK+8LZsvWsXqtZpz1YrePzHr7IoUoYNpOdZqIB/D oJ5Ry/Zg7YCct/4ae0t3CCSt7RveQ2QcbE5olxO666iUG355i6Knvliy7/RbiH64 qJr7ubSWDigYd/6kWrV5I2bRpI4/940yqDxR3YVN4IVO6rL7lkI= =7yVZ -----END PGP SIGNATURE----- --=-=-=--