From patchwork Wed Sep 27 00:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 145137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2374247vqu; Tue, 26 Sep 2023 21:22:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHapONk2jkQQ9sVnHpIlta9jyLzxvdrlWxNEATvQRrxBhgvNGDTP0L2xvict+yieLqzT7Wh X-Received: by 2002:a17:90a:e612:b0:26b:36a4:feeb with SMTP id j18-20020a17090ae61200b0026b36a4feebmr6937888pjy.8.1695788559718; Tue, 26 Sep 2023 21:22:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695788559; cv=none; d=google.com; s=arc-20160816; b=T4dxqza8Fb587sJN0as6bWnOWO6ZPU5OlM9sQmzq/+NuYSfnYerkbmQXB3OzxK/A47 Eca7uerXZo7gfLNlTHptYwkaQNetWCzZUQ8iRWH+4Djcmz9AqZhiNsN8AQ2BLi6yj/Ec U3FQuJrdUd/nikWLqI5B5dkoL6r0QI0Ar0Y8RlYVtj+02ZlFiKIfeazuGrXc82hrOgGM CnKir35XH4kk547zMaSm6nAjXGxUKKC7+z8HrJgJDYmbC5Rn+F49+mZX9WE2Lqj/+3ZC ieH6VIuJs20W1/+qC8pbHrIlfMySJi7VhOfz4scvQp3YtZXjQ5X7q5T/pFqRvv9L8ZVx XmwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HNJwTTZACq9yLQWS8t+PsblAtdyQNZRiQBfSWneDTAI=; fh=l7y1HUlOO7u+Vml4qpaW4w3mcGskM/aOatkAqhOr5mI=; b=0ZCUD1e4Wg0CcpEUqHcp3Cqo2koiS2sYHelqUBJsgDGBAXGvpgkMYNRTy3XGmB35oo dgZrTEZOBwq3RXsG7HkHCeIXPySYWWoRgrvpiGtB8Bz+HNwR8sCTpFmXG+LC8SBcDa6m TiJLHGuzjzVbvl/oSFZTkOHF02ZnnEu9freuPwYLZkxpwYmRdYJZV+eHol8YO3ujkaTk 3IkJGlwZsvxgK1RvN4QMckReSqELe7g9YsHFFgca8mLVXgSKqQZieJI2VFtRQr9fJcJW lpIMkOeLX4oUknu3zG+uB1EKrWDeeJdUcSRwXs6yWIKnwovx4s4vHcsr6WoAizWnO+jc RLSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HOyYLZvZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id s188-20020a635ec5000000b0057404ce2fc8si14747748pgb.529.2023.09.26.21.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:22:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HOyYLZvZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 50E818020BC3; Tue, 26 Sep 2023 21:17:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229634AbjI0ER1 (ORCPT + 26 others); Wed, 27 Sep 2023 00:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjI0EQV (ORCPT ); Wed, 27 Sep 2023 00:16:21 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 799365245; Tue, 26 Sep 2023 17:16:35 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c47309a8ccso81804735ad.1; Tue, 26 Sep 2023 17:16:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695773795; x=1696378595; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HNJwTTZACq9yLQWS8t+PsblAtdyQNZRiQBfSWneDTAI=; b=HOyYLZvZsgGR7Yhfk2SJTVilR1RVXrnU0UrAnyOi6tmSaWCsv0I3m6YiW0uxBkPCUW gnzR4iDuK+vuTflEjZtpRpJyrCQZqkhtD5IIPP+6apTQwiyj79REQjq/U0baFiyoIyOG 8mkUBOht6cqvxtTFaZUH3uDKQ2Qq64OU8NGd4IrMWXrE4JrgwJIvV/rgZXq4RsTvt6hl oKmjJDRBtVenNaXffQJ44XQBebex7pnbwfeP+VKXvHkTQ/og/IEBNnDWHc1l0cPKaHkd 7DTwpgZIxm05ByD/nILLwjSzIaITsKmwJAnpyQCP9OfBGRcPgDQvkrW78Eh1SYLEH1y2 EnQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695773795; x=1696378595; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HNJwTTZACq9yLQWS8t+PsblAtdyQNZRiQBfSWneDTAI=; b=CwwxR7t29v3HCP/awQUmXFiMx7CU9KpzOZXDfspGTHUNkkk6fR2Yw4DFI8sg7xD894 Im37PH2zVU9k4WahGoKteozhQMj20ubm3onVV/Iqe7mxSIF01BrXzYEJJXkEv3H5zolk R47q8pS+k6gzCVyPLw9MPHwV0d0sqtB0pfhr9DsfswH++fYO6LMku7KnUa1d5ngeJ8BO 3Pg1z1bSZEdtW8htX57Tr5Hu1FJqnmR7ST5K6jM9oH3S9hln+BSqRkta+A7B6n/9PEJm zNIt5jAtFJ0IHcfIVQrnYE0KAjETUjo8TW7UPehqxRwhnyZBn/uG0prg/TQf7ZUvcEnF YxYg== X-Gm-Message-State: AOJu0Ywyt9DJXRAbIdj6GGQw+4U18lk//Kc2AfimotQeVbFbaCjA00HK mBFz6ZEqwi6kmi1Myfrkswyw/NBs0o4= X-Received: by 2002:a17:902:d2c7:b0:1b7:f64b:379b with SMTP id n7-20020a170902d2c700b001b7f64b379bmr758925plc.17.1695773794758; Tue, 26 Sep 2023 17:16:34 -0700 (PDT) Received: from wheely.local0.net ([203.63.110.121]) by smtp.gmail.com with ESMTPSA id n5-20020a170902e54500b001b8c6890623sm11703754plf.7.2023.09.26.17.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:16:34 -0700 (PDT) From: Nicholas Piggin To: linux-nfs@vger.kernel.org Cc: Nicholas Piggin , Trond Myklebust , Anna Schumaker , linux-kernel@vger.kernel.org Subject: [RFC PATCH] nfs: reduce stack usage of nfs_get_root Date: Wed, 27 Sep 2023 10:16:23 +1000 Message-Id: <20230927001624.750031-1-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 26 Sep 2023 21:17:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778163184632218236 X-GMAIL-MSGID: 1778163184632218236 Move fsinfo allocation off stack, reducing stack overhead of nfs_get_root from 304 to 192 bytes. Signed-off-by: Nicholas Piggin Reviewed-by: Benjamin Coddington --- Hi, This is motivated by a stack overflow described here: https://lore.kernel.org/netdev/20230927001308.749910-1-npiggin@gmail.com/ NFS is not really a major culprit but it seems not too hard to shrink the stack a little. Thanks, Nick fs/nfs/getroot.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c index 11ff2b2e060f..6e4188c09639 100644 --- a/fs/nfs/getroot.c +++ b/fs/nfs/getroot.c @@ -68,7 +68,7 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) { struct nfs_fs_context *ctx = nfs_fc2context(fc); struct nfs_server *server = NFS_SB(s), *clone_server; - struct nfs_fsinfo fsinfo; + struct nfs_fsinfo *fsinfo; struct dentry *root; struct inode *inode; char *name; @@ -79,19 +79,23 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) if (!name) goto out; - /* get the actual root for this mount */ - fsinfo.fattr = nfs_alloc_fattr_with_label(server); - if (fsinfo.fattr == NULL) + fsinfo = kmalloc(sizeof(*fsinfo), GFP_KERNEL); + if (!fsinfo) goto out_name; - error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, &fsinfo); + /* get the actual root for this mount */ + fsinfo->fattr = nfs_alloc_fattr_with_label(server); + if (fsinfo->fattr == NULL) + goto out_fsinfo; + + error = server->nfs_client->rpc_ops->getroot(server, ctx->mntfh, fsinfo); if (error < 0) { dprintk("nfs_get_root: getattr error = %d\n", -error); nfs_errorf(fc, "NFS: Couldn't getattr on root"); goto out_fattr; } - inode = nfs_fhget(s, ctx->mntfh, fsinfo.fattr); + inode = nfs_fhget(s, ctx->mntfh, fsinfo->fattr); if (IS_ERR(inode)) { dprintk("nfs_get_root: get root inode failed\n"); error = PTR_ERR(inode); @@ -148,11 +152,13 @@ int nfs_get_root(struct super_block *s, struct fs_context *fc) !(kflags_out & SECURITY_LSM_NATIVE_LABELS)) server->caps &= ~NFS_CAP_SECURITY_LABEL; - nfs_setsecurity(inode, fsinfo.fattr); + nfs_setsecurity(inode, fsinfo->fattr); error = 0; out_fattr: - nfs_free_fattr(fsinfo.fattr); + nfs_free_fattr(fsinfo->fattr); +out_fsinfo: + kfree(fsinfo); out_name: kfree(name); out: