Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp321777lqj; Wed, 10 Apr 2024 11:22:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1HKFV9RifnPvR6/kXhx5Tf5fQ8593fWqzH2a4zS+K9iUeegN9OkNKpXEqdvHyavZGsM2zQHalJXV5lzBaYloFE2OCC6uW9AZmjRyElA== X-Google-Smtp-Source: AGHT+IEfD874Ff04ZDt9XMLwop2sPDxJ9KXv+/kMtoINvNRz1FtDQDj4xqf1hlMFl25rYZnS8zlS X-Received: by 2002:a05:620a:4106:b0:78d:675d:cb5f with SMTP id j6-20020a05620a410600b0078d675dcb5fmr932158qko.7.1712773360930; Wed, 10 Apr 2024 11:22:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712773360; cv=pass; d=google.com; s=arc-20160816; b=Oc7xPK45OfOLdzM3JeGtPR8PgR10pll/MrKo4S/0l8IeGNGr9OczSj1wQMK5T5N/J9 SJP8XYOXb8lYlh0im531TCRyz78QhbqI7fS+1UZ0eP9eF3k/ORABrMPfpQH3PBwRSbGl mkxZ4bZOSok1WywRzl72D0+1drNiicnkcCGPEQt8x81w2LjRR0GKjDxddGwT1uqXnDRP n0VyMVrh+TtPZvCgi0KhS0/wDEMUR5Z+64dU8fs572aTpHbnYNgvHoUFFZlgMG1IoIWm S3IAmXjXp0hMzw5srZbIOHaXi8S3TmXRbZM0a4AX7ZFCKMxD74cLKJ8hxMP7gCUUS+t/ orvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=E0capY4vkQMMe4OmQk1Nnkq+/E/rk1CHrRIKnqZDNh4=; fh=P6PH7P1OZVtubWavT0YTS7eLoLoJdRUA+UHwKUdVo7g=; b=j1/XA4MA7Og9Lhm8dVp1fV9se3nwMJb4jZ6/6Z3FP8yCUqCi/vbLPtdVKdp9T/4rxF +UqCKSnzVoP5rOudiGj9zAuTkdagaYarHuuCjxG+MnNe1LDf81BgKzzra4i2TzuIUhLl x53RNy75SnYouMpBkKOM1x97gE/MjZt6lLx+ciz0Uhn4NSi5Ken9brPYolEiGTsmoPJc aP7r+y4Sc/YPqCeMeJS6H1mirmd/9nTbkAoGSvrU9R+newQDD2zIIVQfaN/eCLOvnEXi eFD164ZBDedhTGuga4z7sC0zr7MfxUzXiz79Jm/JMKrzSvTwN9QxRQ1gqwGON1MlFQQV eqow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ancud.ru); spf=pass (google.com: domain of linux-kernel+bounces-139185-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139185-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 26-20020a05620a04da00b0078d60472c4csi9077473qks.223.2024.04.10.11.22.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 11:22:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139185-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ancud.ru); spf=pass (google.com: domain of linux-kernel+bounces-139185-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139185-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5FE861C234DC for ; Wed, 10 Apr 2024 18:22:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E375B1802D1; Wed, 10 Apr 2024 18:22:22 +0000 (UTC) Received: from relay161.nicmail.ru (relay161.nicmail.ru [91.189.117.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C5261802A5 for ; Wed, 10 Apr 2024 18:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.189.117.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712773342; cv=none; b=YokdzCl567T/of5As152EhfMkNnFdiT/FRKmZ7PEJUglDdET3uNBGQZkL1y8n06ybeJudo/XXZhLAseKia7lFMwGJfeA0N9Cw4I5NcKCssbaPxTpqta6e3BybM4uV4V0fH2rQgBiHieB0wgwkHP431A43vneL6NezOqWPoVO3Ng= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712773342; c=relaxed/simple; bh=MiGYtVTPTlPJXtEc1JctOxEO0iGjODSuctCxjwC4WDw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VF6GN/h5N5twoVYbbXKEwuGDp4NoerXKBhlCTdpmjVjAXf0giPyphXtJqEY6jFUXtTDbU3MDd9aKWloCBoWfojP7bedA01041H68R17iASBSRGz1kmEUYUtrdwpoxiEmiWRuEigik+Hhgxz8Qek8E5vvpkpMy7jjmC60NKFefJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ancud.ru; spf=pass smtp.mailfrom=ancud.ru; arc=none smtp.client-ip=91.189.117.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ancud.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ancud.ru Received: from [10.28.138.152] (port=4466 helo=[192.168.95.111]) by relay.hosting.mail.nic.ru with esmtp (Exim 5.55) (envelope-from ) id 1rucF2-0007Tr-4O; Wed, 10 Apr 2024 21:00:13 +0300 Received: from [87.245.155.195] (account kiryushin@ancud.ru HELO [192.168.95.111]) by incarp1104.mail.hosting.nic.ru (Exim 5.55) with id 1rucF2-009gh0-0h; Wed, 10 Apr 2024 21:00:12 +0300 Message-ID: <75c2b85a-da67-4037-b2b5-6a1dec838fa9@ancud.ru> Date: Wed, 10 Apr 2024 21:00:06 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/smpboot: Add map vars allocation check in smp_prepare_cpus_common To: Ingo Molnar Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Ashok Raj , David Woodhouse , linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org References: <20240409182940.664482-1-kiryushin@ancud.ru> Content-Language: en-US From: Nikita Kiryushin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-MS-Exchange-Organization-SCL: -1 Thank you for the feedback! I still have a couple of questions, if you could elaborate further? > - That doesn't really solve anything, nor does it propagate the error > further up. This patch indeed is not fixing the problem, but tries to, at least notify about it. Not sure, if it makes any sense in the context, as noted that > Plus memory allocation failures within __init functions for > key CPU data structures are invariably fatal. If allocation errors in this case are indeed fatal, no one will be able to get the printed warning (so it is indeed pointless). But I do not understand, if all the possible allocation failures here are fatal? For cpu 0 it is obvious (as set_cpu_sibling_map(0) right here dereferences the allocated), but is it as fatal for the other cores? > While there might be > more cores in the future - but there will be even more RAM. This error > condition will never be realistic. In general case it is true. But there are some cases, for which we can not presume, that there will be enough resources: for example, building a new system with large number of cores and test-running it with one small stick of ram, or (more realistically) some quirky hardware/firmware fault. I myself had experience in the past with a buggy BIOS, that made memory resource available for the system usage so small, it led to allocation failures in places it was presumed impossible before. > - The canonical arch behavior for __init functions is to return -ENOMEM > and not printk anything. Thank you for this observation! Is there any documentation I should read to educate myself about conventional rules like that? I was making my assumptions that printk is an OK solution in this case, based on surrounding code (like arch_cpuhp_init_parallel_bringup, disable_smp and native_smp_prepare_cpus, all of which do printk). I guess it may be specific to this specific part of code that, as you mentioned, are not meant to fail. > But that's not really an option for > smp_prepare_cpus_common(), which feeds back into the > ::smp_prepare_cpus() callback that doesn't really expect failure either. > My suggestion would be to simply pass in __GFP_NOFAIL to document that > there's no reasonable allocation failure policy here. Thank you, seems like a more elegant solution, than adding new state flags to the code! But I have some questions considering __GFP_NOFAIL. It clearly shows, that allocation will not fail/is not expected to fail, does it not try making allocation until it succeeds? Would not it make the system hang in a problematic case? If all the allocations for all the cpus in this block are critical, we would be trading a possible crash for a possible hang (all in early startup), not sure which is better to debug. If some of the allocations are not that critical, with __GFP_NOFAIL the would still hang, is it OK? > Also note that this code has changed in the latest x86 tree (tip:master). Thank you for bringing that to my attention! Are there any guides to read about the preferred workflow for patches for x86 subsystem? I was developing the code on top of mainline kernel, not the x86 tree, and would like to know if I should have done it differently for the future.