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 1CB5AC27C4F for ; Wed, 26 Jun 2024 10:53:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A31466B0095; Wed, 26 Jun 2024 06:53:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DF796B0096; Wed, 26 Jun 2024 06:53:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 880106B0098; Wed, 26 Jun 2024 06:53:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6A1DE6B0095 for ; Wed, 26 Jun 2024 06:53:36 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 03B9BA14FD for ; Wed, 26 Jun 2024 10:53:35 +0000 (UTC) X-FDA: 82272728832.13.BBC2302 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by imf17.hostedemail.com (Postfix) with ESMTP id 0AF8340016 for ; Wed, 26 Jun 2024 10:53:33 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kHZ5SFTq; spf=pass (imf17.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.54 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=1719399193; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ra0kofcvGPl3NCrJaksVA0UhehBYPZa3ZeHJvA50SBc=; b=FQyMYaXXMrr5IkjhGl5Qx7XHEBgnme4EHRbNvjS1b1s+KUnwcUM9fYKcBeNAqVeh1dDfFs aoXxLjEa/KsyUS3PZ1T2r30XJjCvbtYyNjz+wPtkjeWa9NGrB3c+ajF/tgrpiWwO+X3qcs Te1REe4ox3Ms9MMOv6U4qbW8inXw+D0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kHZ5SFTq; spf=pass (imf17.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719399193; a=rsa-sha256; cv=none; b=ZvbaVjs30uYTx/5F7zzs7lZgyI41nHUNavXRy6gr0pt12s1i1eg+6C1hXJqW+vi+89hmwl UiER1VtT5PWr+73hy9Iyu71hGpc+Xq5XVNww4rfkfP/RBfHuoxjZD1ZkQoLEnc5y96Zndq OBIwFW2Wuo8sdA1znIQgqjkmSI/NJ6c= Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52caebc6137so6221574e87.0 for ; Wed, 26 Jun 2024 03:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719399212; x=1720004012; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=ra0kofcvGPl3NCrJaksVA0UhehBYPZa3ZeHJvA50SBc=; b=kHZ5SFTqzQNAfLUAlYJqBCQpFd3KKYRuUmJGlxQTrHvBYfEd61Ko5S4WyWqVBj5Uf1 3dudvFiGRb2I0jxgSGqfFUADUxuDRurtcmzxwAienOuunWxvv1okLeQ634zBjVZTVXQ9 JaTEv8o40DiswihdYUdsJwK77EtrzpD6uVC5YG6JNqpemH6o4JgmyuGouAELXSku1HLb CGQJkqD4D/bvLbOA+xxKdgqGS2jRx7z3mYTHs4+KoDmdwDTz+r64hE/BF6R675unFXlb jCeduwV2MVNFLQHo41Og3TbCwL6he+E9lNyWRbTFl8GSn6C4zXSgITh44AcrsgUZmo4f +ojw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719399212; x=1720004012; h=in-reply-to: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=ra0kofcvGPl3NCrJaksVA0UhehBYPZa3ZeHJvA50SBc=; b=u9zmpoOSxQpDK4k/U/JU9ttbt8f8IrMC87mlZ7NkvAesth/E0u1fNeUf7y7DBgt8vd leCvoFjbJY6OY+Bi0nyimnjMvd6tUafSaSa3a2zhR8UIO7DqJtQCjPBP2c9RWAmBsuX+ lyTGP1HeZNVoE79GQ0v9+3XG7s2R2EYpapGEZx/dalOxsRS09r/qqmc/JQLCPxzpTJAU FIy+9sKFgRpO0Xm7epialkVeliMPuIqKwvUkG9pb7cNExVt7S8IzsewI0aPAE3RwZNMZ Bzo5w44yKKC7Qp/w59cvKVm4UN87zRL7W34AtKPAXhsgh7LIleRwN3YSUeXFteEsDKcn yUoA== X-Forwarded-Encrypted: i=1; AJvYcCW5vI8wnHrNSSuT5XGLT0a1vi9zBzVugvAPmRDh0Ke61eo2t5YlAdbzTItF1nr73HpsD2fzOWMpFbTHPYk/NQLDF7c= X-Gm-Message-State: AOJu0YzSvd5qulMIFM7qRz3IdIG2DmfNAPDgwoGMhm5TRPJQ7I7eHTxq zCTd5NjFQ/3y4mWORk7zEhdK1St3W24V5qbP37oAq376D81zHaio X-Google-Smtp-Source: AGHT+IGeS99bKAOeCgtMTOiV4Uvt8+JDU6Dm/+UbirbkklB98PLofRgNc3HgnO5Why9YA3EeIRlLoQ== X-Received: by 2002:a05:6512:39cc:b0:52c:fd46:bf07 with SMTP id 2adb3069b0e04-52cfd46c32bmr2734125e87.49.1719399212035; Wed, 26 Jun 2024 03:53:32 -0700 (PDT) Received: from pc636 (host-90-233-219-252.mobileonline.telia.com. [90.233.219.252]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cdaa5a36asm1427268e87.141.2024.06.26.03.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 03:53:31 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Wed, 26 Jun 2024 12:53:29 +0200 To: Baoquan He Cc: Hailong Liu , 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0AF8340016 X-Stat-Signature: sed9nu9yjpxibpt5u7hgugxdux7yh8kb X-Rspam-User: X-HE-Tag: 1719399213-569188 X-HE-Meta: U2FsdGVkX19OPzoOwEOl9zcQ71LX8qKPvUPib7NayvSTxxqmeHmhy0300kFy0006bTRY0I1qT2V6F5QkP9f5J+MYN5d4nO3zBN/utEA/pHeQvDccZ6FsVsgbJV6rQuUlO9TfX/ml0Kf9Bvtas9Cp2JFqf0SeBBEGEMSufw1TLOfHZoAIhJ+p31xv4aWw6IhjZjmZLipI2/0TwGHwsiMXGPFsAee94JrTY55gjl8dacma9FGQ1wAVtFbIOYMX/yC1ctrpOPh/dyqOvGHu3/OCiVDjL/TkDhoD1Q0yAbS1sl82YOvYcbnQduHH6G82Ztw1VyR0AuB+2y7BzaeNmzMY5wZPdKPRTWtRIXP0GAxb3UEgFrPZ6ZqHbRr1gh1JjMlox0wyJjraacphEiAPIlwq0FhyILifVEGAn+U6ycboIBv4s1fdO6S2aH7yLirOVWyU/Je/8LlpJDxFe7XvjLwU+CBtVa8J5mGEtdy0DfsKPOTzuJY0NYZO9jKm4Tw2OzPb86Wjs4jo+dBuf+b1efxYhl8xhASkXOb6VDJv98TF3Yl9Si/MTWj6E2kVLM5LTQtNNct7ot2A2bgo8UD+z8HRFPP1T8Rv4WoI9ctLvpW4wGIJc0Mc7hdcryT25SYtZPHmg2OBnhuh6epltPxb1FqjmRWVkIlT76UCM8NyOok260fwetmv0EUjuYwXbIZ1Eaxi3xouxLdeyTWvpW314Ori9s/AuL2g8Bar5gA36J7eSHaFbtM7HeJC+23DhJAma7qjlp7CbcbZrbTl7OUHOxEbUwR474YI72Zpry0iOAsymIHpCKDEAwrzekjM8UOVSETpdch+dfGeoGFEPan0bAVWSpMRXyFRxqur/LbTS4h8k6K+cpzBJpXAIrW+CJJAaRxASVnzsYsacl0Zb4ln99mCqc7KRNl0FMhZdizroox9q9ljIcjPZ4zFgd9UL9hvyZGW1Zbcdqs8BblwqmcTSbh WKfUXBtJ BpOjwTmEAv1roGZ6PgNixetfG1v18BZt9wG0ntmNagNTLB1kTly1rvldN6StySaO8XJw6/9HXEbxKBvTfKQ0deacks6Ec8mnB+LcWP78FYU3R8RureVGPnq3JPSntLZIbSFpc2d8Ii0v++WZdRSdq8vrcQJEvK42FZSg4t5BYlK+riEIS0xSsS5o0uA/sd4aGXKbKEGcdPFeG+gI1Z/z6FxoW+xzx+knA0kX7M50YvowQQKMC1PwgFiRvIPMue1PR07LstFqmt/qzERkwH92MHD8/LNOPzXZc9a5gvIYIPai+Ixo/8VXO3XORCIm1F8/e9jnFs7TnkXAdNFGmCHwo2V4SpE/DaDgmxTyyzKsPhw7L4p02aQreyHC9Xw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000045, 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 06:51:32PM +0800, 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. > > > > > > > > > > > > > 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; > } > Just submitted the same :) I will send out the patch. -- Uladzislau Rezki