Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp395290rdb; Thu, 2 Nov 2023 06:57:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IED6gpOFoZKpTcGuF5skVWnV+cEgg9oIOpG4gMZQFraqm/uBpXa/DzXM3XHncGvGsOHGXNy X-Received: by 2002:a05:6358:e496:b0:168:f602:d61 with SMTP id by22-20020a056358e49600b00168f6020d61mr15746304rwb.32.1698933442759; Thu, 02 Nov 2023 06:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698933442; cv=none; d=google.com; s=arc-20160816; b=BRWyDUzsT+ekWvz6k82UyS+4nrOmpHlkVB4livmD75RcyyRbGarPg21kxLZU9fwvql SeGXblVMPqqoTfoJLnCyvb1qILQjo4RXUfhqZryXoj7YsQ/byeqNCf7pz7tBF9S2VVVS mjrJzungBuQ3rJllZDZKb5uSMGzof9OMllOrNQuCcwAEH22Ms/6A5G8em+DQAgQx3vdG KUYHGi5qt13QMzyB1V40Ivh2RwYr+LmTZP4A0uFWSYOlCUaTwjjx7lgtcue8l09VnmAf CFPweYuwDakz5CBudNQxEQBFoX7VfaWBSJq+t2jEludndEWD5xK1hIH2yhls51F/m0ba doqg== 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=5TEd+F0YQyk/1TwoiDrOVtemsr3oUTqyHEkw4uj9jvw=; fh=4bG/vbCyzhxhXa8hCKbj98tP2emGZ8iQ8k7xa4nidbo=; b=ekwWgeyC3C/DJIcUz3XPkFEsbwAGZehUkQD51HY1bVNSndY+d/EWnOwPhFpnLKNcJy 7QtSTE/H7qPm8+/DW8hgCN4VWv0bYI3KQNivHXo6SKUOeu3VnIFIZfsFdKm4n5wL4IuX 7xDOPAu/UsXRnuGu1dlx4FDPBpXWlas8JgC2S49LP9h4/etZdBb7HRxTLTzkYm/jvlcS lVh10EYwU8Ru/YXTeupPivh/zg4oW3QKjkMU6JTnqEXQ0TEw4Xxgibmw5WevtUwG0lQG QMejcDI4xCW584JHb/kXqbNGLLfuX/MmEUuLYWGFCO8HpMiqiqhdVBxspZOaN9k55msk xhUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XIoqOl5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v69-20020a638948000000b005aebc9096d4si1829808pgd.150.2023.11.02.06.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 06:57:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XIoqOl5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id AB71180A4ADD; Thu, 2 Nov 2023 06:57:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376693AbjKBN4c (ORCPT + 99 others); Thu, 2 Nov 2023 09:56:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229713AbjKBN43 (ORCPT ); Thu, 2 Nov 2023 09:56:29 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0A28A6; Thu, 2 Nov 2023 06:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698933383; x=1730469383; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=TdsHsMA7CiZ4zuc20AAZXAmmV5t7rmocsbstMG+zpxY=; b=XIoqOl5eHS0unkSt7v5oeJwQafGo+pvwxRpDa0FBfIWbLCs6eRLUqkXB H0vyJRfb0L6q303f8mbY0GCM9/5ebCojS1Sy8Qkf0IiwbNJlFVeA5lXCX dubvHu4W2fHoWES0jhvsZ05S1FTDJcLEzl3N4qP/F/j4mh1mNWVCzO9QC b7fFV90/hHF9ZHoNWDdQ1jKh2yvwzFQHCEzI7rozfum3kf80TpLbo+bRK FiiX03ptprXmhYQMX0PPwVZaw57cMkWqjxNAzqsFm4VouAvnLPFTb/mS1 R4ChoYtL/3u11S+v/MFiFbTvLTV0fvMODNivy5K4vhecZX0GQxdsDqivF g==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="368058969" X-IronPort-AV: E=Sophos;i="6.03,271,1694761200"; d="scan'208";a="368058969" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2023 06:56:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,271,1694761200"; d="scan'208";a="8997684" Received: from arajan-mobl.amr.corp.intel.com (HELO box.shutemov.name) ([10.251.215.101]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2023 06:56:15 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 0B33910A312; Thu, 2 Nov 2023 16:56:12 +0300 (+03) Date: Thu, 2 Nov 2023 16:56:11 +0300 From: "Kirill A. Shutemov" To: Michael Roth Cc: Vlastimil Babka , Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@kernel.org, Nikolay Borisov , Bandan Das Subject: Re: [PATCHv2] efi/unaccepted: Fix soft lockups caused by parallel memory acceptance Message-ID: <20231102135611.lyiu2lss2csswgch@box.shutemov.name> References: <20231016163122.12855-1-kirill.shutemov@linux.intel.com> <20231016205419.c3sfriemyaiczxie@amd.com> <3ccb822e-fc46-3087-d6ad-2f754dcf218c@suse.cz> <20231101004523.vseyi5bezgfaht5i@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231101004523.vseyi5bezgfaht5i@amd.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Thu, 02 Nov 2023 06:57:19 -0700 (PDT) On Tue, Oct 31, 2023 at 07:45:23PM -0500, Michael Roth wrote: > > If you mean the guest has as many cpus as the host provides to it, but you > > stress with many more than that number of processes, then I wonder how > > Yes, this is what I meant. If there are more memory-hog worker threads in > the guest than there are vCPUs, I'm better able to reproduce soft-lockups. > That sort of makes sense since those threads will spend more time waiting on > an available vCPU to handle memory acceptance. > > But it actually isn't a requirement, I've also been able to reproduce this > with equal numbers of worker threads and vCPUs if I run 4 VMs, each > running the stress/acceptance workload at the same time. > > And if I force 4K pages in gmem backend (technically a supported > configuration) then I can reproduce it much more easily since the 2MB > acceptance path takes much longer and it makes it easier to expose any > potential remaining concurrency issues. This all sounds like we are solidly in "system is overloaded" territory. Soft-lockups are still not good in this case. But I am not sure what we can do about it. One silly idea is to prevent all vCPUs to do accept simultaneously and reserve one (or several) to do housekeeping. The idea is that this vCPU can be preempted to do job on other tasks. It would only make a difference for PREEMPT_FULL case and if the housekeeping CPU will hit the accept path from preemptable context. And it is obviously not applicable if there's only single vCPU. > > softlockups would happen due to the extra processes. Since irqs are disabled > > through the whole operation, the extra processes can't become scheduled, and > > not being scheduled due to overloading doesn't trigger softlockups, hmm... > > The soft lock-ups happen as soon as IRQs are re-enabled, either: > > a) right after a thread sees that its range intersects something > that's in the process of being accepted > > b) right after a thread finishes accepting its whole range and is > about to return from accept_memory() > > I see a) occur more in the 4K test scenario, b) is more difficult to > reproduce and seems to need a larger system to reproduce more reliably. I am not sure why you differentiate these scenarios. Kernel just hits place where it can be preempted and observes that it is overdue to scheduling. > The fact that b) seems to depend on larger systems sort of makes sense. > When we need to covert a page to private as part of accepting it, there > is a guest->host request that eventually goes off to host userspace which > will call the KVM ioctl KVM_SET_MEMORY_ATTRIBUTES to mark the memory as > private so that it will get faulted in from the guest_memfd backend. When > this happens, any guest page faults that are currently in flight will get > invalidated and require a retry, and there's also a guest TLB flush > that results in an NMI to all the cores the guest was scheduled on so that > it can exit and acknowledge new updates. So the higher the rate of > KVM_SET_MEMORY_ATTRIBUTES the system is able to process, the higher the > frequency of this sort of activity on the host side that can impact each > vCPUs ability to make progress on accepting a particular range. > > Also I was running 4 guests, each with as many vCPUs as the host, so > contention for physical resources would probably be a factor as well. Yeah, at some point you will just saturate memory bandwidth. > I'm not sure what can be done about b), but they seem to be host-side > optimizations that aren't too relevant to this patch, and they seem to > occur less frequently than a), which seems to be more guest side. > > Still not sure what is causing type a) lock-ups exactly, but through > various traces and debug statements I think I've at least gotten some idea > that there are certain conditions where the vCPUs become more and more > dependent on each other completing certain ranges, and they spend longer > and longer amounts of time looping through the accepting_list. > > There are 3 things I've noticed that might lead to vCPUs getting hung up > on each other: > > 1) try_to_accept_memory_one() calls accept_page(page, MAX_ORDER), which > is a 4MB range This should not make one vCPU to setup on work on another. Page allocator owns full 4MB. It is not shared with anyone. > 2) There's an extra 2MB region taken after each unit to account for > load_unaligned_zeropad() Okay, yes, this is true. > 3) There is what appears to be a bug here: > > list_for_each_entry(entry, &accepting_list, list) { > if (entry->end < range.start) > continue; > if (entry->start >= range.end) > continue; > > where if entry->end == range.start, the thread will wait on the owner > of that range even though it doesn't actually intersect. Good catch. Care to send a patch? > I don't quite know how all this lines up to a dependency chain that would > potentially explain the lock-ups, but to mitigate that scenario, I tried only > adding the specific 2MB range that is being accepted to accepting_list, rather > than the whole range, and then just iterate through 2MB at a time in > accept_memory() instead of passing the larger range on to arch_accept_memory(). This might improve situation with soft lockups a bit, but would hurt accept bandwidth. > That seems to have resolved the soft lock-ups for the forced-4K scenario, but > I haven't had much time to test larger configurations yet. -- Kiryl Shutsemau / Kirill A. Shutemov