Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2541672rwd; Wed, 14 Jun 2023 04:30:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4uTXlS5Bi00Iuog/pafj5pHODGnx+N6aYMCpKCEl9jx29JSBgrRIOIzkVo6z4RWZ7DgEly X-Received: by 2002:a17:902:6b8b:b0:1b1:b50c:e330 with SMTP id p11-20020a1709026b8b00b001b1b50ce330mr10157243plk.2.1686742243170; Wed, 14 Jun 2023 04:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686742243; cv=none; d=google.com; s=arc-20160816; b=X6B5IdN+Ane3sJZ+yA2Zqxo6QbaRARk83NFoRumBSJLmuSu+9+BxjI5pA5fquFq7Lk 3hlfZWO7RA5g/hElT6KSRT4VMvqYgySRyVRL9Rrv0S/WJpRdLLhPMpWD8mZHpWEK2sxJ 0k0xpIcFFhWmkznMKnb79dIE8MM2wmAZ9TVjr2OzjWnt5HZSUwg1JBO2swDPPF7jcDtU aZBMZRs6RXjoU2yAdFC9x2Ob0tgrCIOO2semxNFNZ9XhsYS3NWtf1qjxwjRxuaYV8Gsb RI+ZkMUiv9FeHMlamI15DwsuR26599CF7oPufc5QImOiox9djkYzMejkimwFXAkhDnqa HQ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WhOu0XxN6uhlmRMWT5HlnNaXNdcEQwTVJ0R+gre2Hng=; b=enpQzWh0IohUtvznKXV1+z3py8GUspVwK33/TvfJ1IUuI8X/maaRYIfMsQ5Gjx3j5V 57iY0KwwkwIQP6T9vWWFmA9ZXOvDD4NWzg91dyme0X4NeEei9EI3hHk0k/hL2yZ9mz9V KrQA7vx73qQ+vKXOcHn+oi/U8UXTip2v3Vsb2rD7Zd6DsZTMv4Ciw51YoSFLlSkxEtQu JNcMgyzjnG/q5fot5iKQimThzQ+nzKjbsIMVM1ecw3UIwkHl71ckY0Qscyup3jukmhGd kSlD+30WZ5ISGFBimV7JHUnDSxKlybJLVc5UP+fGbwzY3B4qHM9HUaaO8fvYJIEOmzQH pO8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="2Dvsaip/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a170902daca00b001b19ceca240si2565168plx.169.2023.06.14.04.30.30; Wed, 14 Jun 2023 04:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="2Dvsaip/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236017AbjFNLQt (ORCPT + 99 others); Wed, 14 Jun 2023 07:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236538AbjFNLJu (ORCPT ); Wed, 14 Jun 2023 07:09:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B0371BC3 for ; Wed, 14 Jun 2023 04:09:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C498F629BB for ; Wed, 14 Jun 2023 11:09:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A84C3C433C8; Wed, 14 Jun 2023 11:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686740988; bh=QlLA8ehxT/VDQBjkSwCszlwern9Sc5B23YkkiyOKqUI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=2Dvsaip/e3rSwQLYF2uKMQQ0FhSwfibEEHJRzl1bxV8Kt8EBXlSKgt1vtjw5mqv6Y BYEDnJ7Pjke3cJO3da1vvqKZ8sO6ZG2MJY/VvBkR5xo3po463zmUG6p7ibGRUK54g0 sxMVML4nymFhYW8j5jI2Wp1X1WfLKZxBP2SiFe4Y= Date: Wed, 14 Jun 2023 13:09:45 +0200 From: Greg KH To: Yajun Deng Cc: rafael@kernel.org, rppt@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/mm_init.c: remove spinlock in early_pfn_to_nid() Message-ID: <2023061431-litigate-upchuck-7ed1@gregkh> References: <20230614110324.3839354-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230614110324.3839354-1-yajun.deng@linux.dev> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 14, 2023 at 07:03:24PM +0800, Yajun Deng wrote: > When the system boots, only one cpu is enabled before smp_init(). > So the spinlock is not needed in most cases, remove it. > > Add spinlock in get_nid_for_pfn() because it is after smp_init(). So this is two different things at once in the same patch? Or are they the same problem and both need to go in to solve it? And if a spinlock is not needed at early boot, is it really causing any problems? > > Signed-off-by: Yajun Deng > --- > drivers/base/node.c | 11 +++++++++-- > mm/mm_init.c | 18 +++--------------- > 2 files changed, 12 insertions(+), 17 deletions(-) > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index 9de524e56307..844102570ff2 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -748,8 +748,15 @@ int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) > static int __ref get_nid_for_pfn(unsigned long pfn) > { > #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT > - if (system_state < SYSTEM_RUNNING) > - return early_pfn_to_nid(pfn); > + static DEFINE_SPINLOCK(early_pfn_lock); > + int nid; > + > + if (system_state < SYSTEM_RUNNING) { > + spin_lock(&early_pfn_lock); > + nid = early_pfn_to_nid(pfn); > + spin_unlock(&early_pfn_lock); Adding an external lock for when you call a function is VERY dangerous as you did not document this anywhere, and there's no way to enforce it properly at all. Does your change actually result in any boot time changes? How was this tested? thanks, greg k-h