From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03B95C27C4F for ; Wed, 26 Jun 2024 11:45:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 705716B0089; Wed, 26 Jun 2024 07:45:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B4EB6B0092; Wed, 26 Jun 2024 07:45:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 555996B0093; Wed, 26 Jun 2024 07:45:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 35D3D6B0089 for ; Wed, 26 Jun 2024 07:45:30 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DB465C0F26 for ; Wed, 26 Jun 2024 11:45:29 +0000 (UTC) X-FDA: 82272859578.29.3E3D7A2 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf05.hostedemail.com (Postfix) with ESMTP id D6D36100005 for ; Wed, 26 Jun 2024 11:45:27 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Mrwu9JPK; spf=pass (imf05.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719402311; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FtIudqgscH1tmYZ80Jw6C5/Pb0juTqicPUasIrRpqJY=; b=TsLIHWeew339EQsYbiO3g9kx1k6QPYGx5XvXdCdvBMGCSBuZTxr/Y7fO1ICUXnvyHuCnmj zaD6K+yaKP2Apn69Ix79H+fSxSV8ifpGcHoYeIQ6EKMJ2CgBFqGrNAwVz3TYwpQrrYNdQ+ CMIMxQqGkqy0nLRseN1OTaJuq8CXLqs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719402311; a=rsa-sha256; cv=none; b=gsmz60qBpL8uUC6pONREQNq0o0JYw+/3WQOsi/SY1OOiarbyCXr4GGX8TV5xkuPndiAnfd TK6T7axxACQkDwi3oJI2uLU27es/I2Pty12uMjbyXy6A2CRDpGfmj66shnhtvPRZ+TBa0+ J7fD4yjoECEYjjzrzxRVgryLI2hc7iE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Mrwu9JPK; spf=pass (imf05.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-57cbc66a0a6so154119a12.1 for ; Wed, 26 Jun 2024 04:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719402326; x=1720007126; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=FtIudqgscH1tmYZ80Jw6C5/Pb0juTqicPUasIrRpqJY=; b=Mrwu9JPKzzXJDe+G2+4eH5mW96vuJ8mYNCBZowHRcCweK8koWtcOtXy5DsOiRhJsps cFOH1gobbjfTtaqwB66iso6oEDJLZGzgJVvCUqwzxfvr4SyaeMecwv+hvh1KVijaWxbg aM9ldUlPQ+ldY7v3zm56tz+Wes7rjofVKgBvJewj5/2BpM/p9s1xDDSOyKbu+ez+dqYO k/RP09jjkQGcwfITJCfhn4o88I4JWCpC4fXNfApGn1fQ8W1xLBGYwXgpyG83KYmUHL7c YhVvLNA3uQikX9Dp4hRS0Q2xCJV+epu2gd5ivapuSuti6qj8rVcv0SzzrJ80EnkxCCSI IGJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719402326; x=1720007126; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FtIudqgscH1tmYZ80Jw6C5/Pb0juTqicPUasIrRpqJY=; b=gW+yoa5bz+zvDmvKHHMbbsQkcQ/U/J2Jj3FfvQ50JS3qpc5Z6Jb7ubkRKDnVi6eCTs X6kZjI9MX4mMDko3buZcOT47S1DSpZ4G8fveJb5osm7n4h5XFf6c6i31+sqxuGSFjHrl Iiln7dsXl812Fsgq4W1xnKQH/CtZraKd0t+Nulbcv1GQqzMWGL5zKdVGr0QcPKAT7CB4 cKUqjd5PJbPgRL0pwROvxYmctvzz39NALsbv8AClSWWdrTPqSi48+PcaI7zAJY5Wzsml 6zoHo9/FOZnuK+OcIWP2azt9vvp1r6NwxkyTrQwJkimqDwHBPjQ9/kYADyzQQu7EHog4 eViQ== X-Forwarded-Encrypted: i=1; AJvYcCV08F/625AVthvzZmjwIaCBkVQmTbpuHB9EFCz03Ot+KPUp69iY8a4bl+kVU0SLlvtAEP4IhbiBWFnFnWaDH9Emw5k= X-Gm-Message-State: AOJu0YxEX6FrNZ/1w8XehxVmTgNegPjl2SVf/F271v6c7/oDirXw8Dxk LRVgqbLdg/IFt22priO8rvajSIe95Yp3P7dvzoMrzJoOMX5Wbjf3 X-Google-Smtp-Source: AGHT+IG6GDqMRzNCz++Fc2S1dNLryT/7sfAReEErY8zDzCYcNLhwGyQs5luxS5bcQEnXEIZw4svCRg== X-Received: by 2002:a05:6402:34c6:b0:57d:45af:112c with SMTP id 4fb4d7f45d1cf-57d45af127amr10658219a12.4.1719402326149; Wed, 26 Jun 2024 04:45:26 -0700 (PDT) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-582c51c9ac9sm1366295a12.58.2024.06.26.04.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 04:45:25 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Wed, 26 Jun 2024 13:45:24 +0200 To: Hailong Liu Cc: Baoquan He , Uladzislau Rezki , Nick Bowler , linux-kernel@vger.kernel.org, Linux regressions mailing list , linux-mm@kvack.org, sparclinux@vger.kernel.org, Andrew Morton Subject: Re: PROBLEM: kernel crashes when running xfsdump since ~6.4 Message-ID: References: <20240626051206.mx2r4iy3wpexykay@oppo.com> <20240626100342.2dudj6fjjx6srban@oppo.com> <20240626113039.a2rvjarq6zbrgjis@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240626113039.a2rvjarq6zbrgjis@oppo.com> X-Stat-Signature: k56nk7ko1ftn8xmdmb9mqe84o17969h4 X-Rspamd-Queue-Id: D6D36100005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719402327-286819 X-HE-Meta: U2FsdGVkX19MTYty5503gYAwdqu5ibHu5nSlDG0N21ZKphMD/PfcAQW+BrsI/NsBYSBPX2bO8B7CKhmjbCT5ulhF5dpZdkaa3XXRx60MmW2sTy5Jw1ahFOBvlJyVjIxcf8dGGianCELdn9FZ5Xw9cuiHU62SnSmilq6RRX0uaOAxs774LmBaJwp6EFGgX5yw6KeDpfpiiGQgmJLG3X6el9uaRQ2Gpvc1gRYb49RZSL71Qzau6+g4X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uF+LqmhXbPOfqnZcGBe5VxPW7GxHPd0sCHgJ0UAdM48= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000338, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jun 26, 2024 at 07:30:39PM +0800, Hailong Liu wrote: > On Wed, 26. Jun 18:51, Baoquan He wrote: > > On 06/26/24 at 06:03pm, Hailong Liu wrote: > > > On Wed, 26. Jun 11:15, Uladzislau Rezki wrote: > > > > On Wed, Jun 26, 2024 at 01:12:06PM +0800, Hailong Liu wrote: > > > > > On Tue, 25. Jun 22:05, Uladzislau Rezki wrote: > > > > > > > > > > > /** > > > > > > > > > > > * cpumask_next - get the next cpu in a cpumask > > > > > > > > > > > * @n: the cpu prior to the place to search (i.e. return will be > @n) > > > > > > > > > > > * @srcp: the cpumask pointer > > > > > > > > > > > * > > > > > > > > > > > * Return: >= nr_cpu_ids if no further cpus set. > > > > > > > > > > > > > > > > > > > > Ah, I got what you mean. In the vbq case, it may not have chance to get > > > > > > > > > > a return number as nr_cpu_ids. Becuase the hashed index limits the > > > > > > > > > > range to [0, nr_cpu_ids-1], and cpu_possible(index) will guarantee it > > > > > > > > > > won't be the highest cpu number [nr_cpu_ids-1] since CPU[nr_cpu_ids-1] must > > > > > > > > > > be possible CPU. > > > > > > > > > > > > > > > > > > > > Do I miss some corner cases? > > > > > > > > > > > > > > > > > > > Right. We guarantee that a highest CPU is available by doing: % nr_cpu_ids. > > > > > > > > > So we do not need to use *next_wrap() variant. You do not miss anything :) > > > > > > > > > > > > > > > > > > Hailong Liu has proposed more simpler version: > > > > > > > > > > > > > > > > > > > > > > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > > > > > > index 11fe5ea208aa..e1e63ffb9c57 100644 > > > > > > > > > --- a/mm/vmalloc.c > > > > > > > > > +++ b/mm/vmalloc.c > > > > > > > > > @@ -1994,8 +1994,9 @@ static struct xarray * > > > > > > > > > addr_to_vb_xa(unsigned long addr) > > > > > > > > > { > > > > > > > > > int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus(); > > > > > > > > > + int cpu = cpumask_nth(index, cpu_possible_mask); > > > > > > > > > > > > > > > > > > - return &per_cpu(vmap_block_queue, index).vmap_blocks; > > > > > > > > > + return &per_cpu(vmap_block_queue, cpu).vmap_blocks; > > > > > > > > > > > > > > > > > > > > > > > > > > > which just takes a next CPU if an index is not set in the cpu_possible_mask. > > > > > > > > > > > > > > > > > > The only thing that can be updated in the patch is to replace num_possible_cpu() > > > > > > > > > by the nr_cpu_ids. > > > > > > > > > > > > > > > > > > Any thoughts? I think we need to fix it by a minor change so it is > > > > > > > > > easier to back-port on stable kernels. > > > > > > > > > > > > > > > > Yeah, sounds good since the regresson commit is merged in v6.3. > > > > > > > > Please feel free to post this and the hash array patch separately for > > > > > > > > formal reviewing. > > > > > > > > > > > > > > > Agreed! The patch about hash array i will post later. > G> > > > > > > > > > > > > > By the way, when I am replying this mail, I check the cpumask_nth() > > > > > > > > again. I doubt it may take more checking then cpu_possible(), given most > > > > > > > > of systems don't have gaps in cpu_possible_mask. I could be dizzy at > > > > > > > > this moment. > > > > > > > > > > > > > > > > static inline unsigned int cpumask_nth(unsigned int cpu, const struct cpumask *srcp) > > > > > > > > { > > > > > > > > return find_nth_bit(cpumask_bits(srcp), small_cpumask_bits, cpumask_check(cpu)); > > > > > > > > } > > > > > > > > > > > > > > > Yep, i do not think it is a big problem based on your noted fact. > > > > > > > > > > > > > Checked. There is a difference: > > > > > > > > > > > > 1. Default > > > > > > > > > > > > > > > > > > ... > > > > > > + 15.95% 6.05% [kernel] [k] __vmap_pages_range_noflush > > > > > > + 15.91% 1.74% [kernel] [k] addr_to_vb_xa <--------------- > > > > > > + 15.13% 12.05% [kernel] [k] vunmap_p4d_range > > > > > > + 14.17% 13.38% [kernel] [k] __find_nth_bit <-------------- > > > > > > + 10.62% 0.00% [kernel] [k] ret_from_fork_asm > > > > > > + 10.62% 0.00% [kernel] [k] ret_from_fork > > > > > > + 10.62% 0.00% [kernel] [k] kthread > > > > > > ... > > > > > > > > > > > > > > > > > > 2. Check if cpu_possible() and then fallback to cpumask_nth() if not > > > > > > > > > > > > > > > > > > ... > > > > > > + 6.84% 0.29% [kernel] [k] alloc_vmap_area > > > > > > + 6.80% 6.70% [kernel] [k] native_queued_spin_lock_slowpath > > > > > > + 4.24% 0.09% [kernel] [k] free_vmap_block > > > > > > + 2.41% 2.38% [kernel] [k] addr_to_vb_xa <----------- > > > > > > + 1.94% 1.91% [kernel] [k] xas_start > > > > > > ... > > > > > > > > > > > > > > > > > > It is _worth_ to check if an index is in possible mask: > > > > > > > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > > > index 45e1506d58c3..af20f78c2cbf 100644 > > > > > > --- a/mm/vmalloc.c > > > > > > +++ b/mm/vmalloc.c > > > > > > @@ -2542,7 +2542,10 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue); > > > > > > static struct xarray * > > > > > > addr_to_vb_xa(unsigned long addr) > > > > > > { > > > > > > - int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus(); > > > > > > + int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids; > > > > > IIUC, use nr_cpu_ids here maybe incorrect. > > > > > > > > > > take b101 as example, nr_cpu_ids is 3. if index is 2 cpumask_nth(2, cpu_possible_mask); > > > > > might return 64. > > > > > > > > > But then a CPU2 becomes possible? Cutting by % nr_cpu_ids generates values < nr_cpu_ids. > > > > So, last CPU is always possible and we never do cpumask_nth() on a last possible CPU. > > > > > > > > What i miss here? > > > > > > > Sorry, I forget to reply to all :), I write a demo to test as follows: > > > > > > static int cpumask_init(void) > > > { > > > struct cpumask mask; > > > unsigned int cpu_id; > > > cpumask_clear(&mask); > > > > > > cpumask_set_cpu(1, &mask); > > > cpumask_set_cpu(3, &mask); > > > cpumask_set_cpu(5, &mask); > > > > > > cpu_id = find_last_bit(cpumask_bits(&mask), NR_CPUS) + 1; > > > pr_info("cpu_id:%d\n", cpu_id); > > > > > > for (; i < nr_cpu_ids; i++) { > > > pr_info("%d: cpu_%d\n", i, cpumask_nth(i, &mask)); > > > } > > > > > > return 0; > > > } > > > > > > [ 1.337020][ T1] cpu_id:6 > > > [ 1.337338][ T1] 0: cpu_1 > > > [ 1.337558][ T1] 1: cpu_3 > > > [ 1.337751][ T1] 2: cpu_5 > > > [ 1.337960][ T1] 3: cpu_64 > > > [ 1.338183][ T1] 4: cpu_64 > > > [ 1.338387][ T1] 5: cpu_64 > > > [ 1.338594][ T1] 6: cpu_64 > > > > > > In summary, the nr_cpu_ids = last_bit + 1, and cpumask_nth() return the nth cpu_id. > > > > I think just using below change for a quick fix is enough. It doesn't > > have the issue cpumask_nth() has and very simple. For most of systems, > > it only adds an extra cpu_possible(idex) checking. > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > index 633363997dec..59a8951cc6c0 100644 > > --- a/mm/vmalloc.c > > +++ b/mm/vmalloc.c > > @@ -2542,7 +2542,10 @@ static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue); > > static struct xarray * > > addr_to_vb_xa(unsigned long addr) > > { > > - int index = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus(); > > + int index = (addr / VMAP_BLOCK_SIZE) % nr_cpu_ids; > > + > > + if (!cpu_possible(idex)) > > + index = cpumask_next(index, cpu_possible_mask); > > > > return &per_cpu(vmap_block_queue, index).vmap_blocks; > > } > > > Agreed! This is a very simple solution. > > If cpumask is b1000001, addresses being distributed across different > CPUs could theoretically lead to such a situation, but it has not been > encountered in practice. I’m just pointing out the possibility here. > > CPU_0 CPU_6 CPU_6 CPU_6 CPU_6 CPU_6 > | | | | | | > V V V V V V > 0 10 20 30 40 50 60 > |------|------|------|------|------|------|.. > Right! > > Thanks again for your reply, I learned a lot. > Thank you for helping :) -- Uladzislau Rezki