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 3791ACDB482 for ; Fri, 13 Oct 2023 16:44:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5F8D80060; Fri, 13 Oct 2023 12:44:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0FDD8D0015; Fri, 13 Oct 2023 12:44:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AFE780060; Fri, 13 Oct 2023 12:44:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7B04E8D0015 for ; Fri, 13 Oct 2023 12:44:51 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4A385A040C for ; Fri, 13 Oct 2023 16:44:51 +0000 (UTC) X-FDA: 81341012382.13.9654AA4 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf01.hostedemail.com (Postfix) with ESMTP id D24654001B for ; Fri, 13 Oct 2023 16:44:48 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=UQRotTIH; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=+WUoplQ8; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697215489; a=rsa-sha256; cv=none; b=57bmeeSK0shwx4z7rBtFqKY2c8l7R0gcLd/Zv9R0Lt4OoC075AExHuHyKs9Z3QNCelevWi P7sr9RTiCz1NH//ka8Swc5BYhPmY/bbQlecR+bWKYoQLVz+siQUaSWe34hCsqfb//obKv6 0/chQ4fHQ5Xp5J+0vzmCLV7+AXVqRUI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=UQRotTIH; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=+WUoplQ8; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697215489; 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=JqX75Zi0TdK1SmGPAZ5miYmrbIOPlJaIeQlD1x+zdUg=; b=ee2JFj18DYzOCa2MuvMZxOle5dfbRFBLtEqrG/tdrtBRvoT8CqoBfqAS36YF6EyTOa/cHY Xb/sUKMflYBoBc9nWAGJNxe6ZdPCWBGc6fBSvMEIdiD8qxuz76fuorn9/3ee8Xmt0LEWyo WYHO6l+pkbEFypzMgrlXVRyTQutzd+E= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 64602210DD; Fri, 13 Oct 2023 16:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1697215486; h=from:from:reply-to: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; bh=JqX75Zi0TdK1SmGPAZ5miYmrbIOPlJaIeQlD1x+zdUg=; b=UQRotTIHMoU/AK0y+quvKMhR2J/LCldJHRe/w5Np0WFVyCYulv9ffRb6tz8F6DN4p+YB0r sw99P4r48hO5nV9Ao3oGF50Hq93oHTVwca2vF1bxWM953FWXLsAa2kxx8KCFNT7wxyAoUi xinBMa7CngkECPtSLczQKzwDH1l7rO0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1697215486; h=from:from:reply-to: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; bh=JqX75Zi0TdK1SmGPAZ5miYmrbIOPlJaIeQlD1x+zdUg=; b=+WUoplQ8+AqVFXsmtjtdqC9+eroodPLlAmARY9dR3HwLQB3ll+qQ4e5W3MvsWBz/pHWlR6 gh4V2NzRf0SOlMDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0198E1358F; Fri, 13 Oct 2023 16:44:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Ey0IO/1zKWVtcgAAMHmgww (envelope-from ); Fri, 13 Oct 2023 16:44:45 +0000 Message-ID: <34d94c58-f5f3-48eb-5833-0ef0c90cf868@suse.cz> Date: Fri, 13 Oct 2023 18:44:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCHv14 5/9] efi: Add unaccepted memory support To: "Kirill A. Shutemov" , Michael Roth Cc: 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, khalid.elmously@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 References: <20230606142637.5171-1-kirill.shutemov@linux.intel.com> <20230606142637.5171-6-kirill.shutemov@linux.intel.com> <20231010210518.jguawj7bscwgvszv@amd.com> <20231013123358.y4pcdp5fgtt4ax6g@box.shutemov.name> <20231013162210.bqepgz6wnh7uohqq@box> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20231013162210.bqepgz6wnh7uohqq@box> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D24654001B X-Stat-Signature: zgnumjxzdzk5y6bqo34agegq4689yqkk X-Rspam-User: X-HE-Tag: 1697215488-517716 X-HE-Meta: U2FsdGVkX1+u/ooy+NCTM1zcugjRbY1H2z9+Jh62s51eO5LInvPTc1lU5yOiJmhKy4tN3egckWV1w1ByVqANmhlbgVQa2/xVV3VySlIxxgTaDHk7da2jCrNDx5inJJTDS46mDwt4AYVMBxKTt05SeL/O9OaGo5OZVnIg7jghRtPK1MbH1rJmhAqoCL0reNCanlc0isJ06EGzAHqg0v3Or24OX2eHdNn/s6T3ql4SpWT+gWlj8IYJuq9gtbXdvwjwc4UeJ/zma8K3KxU6fIwBKiD1sAKLxA79d+3e5sgHHql/Qv9xUNNLvgflSpst4VPP7apl2Ruw9ovt+oS7mMDQ/HpurWKhAnr+Vlsmmfw9lyzUn87kFtVY8rHZCxKMqwOUeXxxfw1NX7qHgmQHat6IDicO4Cn22mUAC7nY4IkUeSZtd+ZPI8bDPSa9eiak7mUGxinyP4uUiLv+SjTOD8vw0kpapAvcvvV+bju49J817w0hbhqbmUF45oL6rZ3UQo5Kaqa0G90ZBexUE/NAwqcD86anvYENgZduCrUOMqy+liw2GieRewpuWtMfNd8Sa4Hg6wagZOpaW/0hPS4I3Y2Z2YxLyc75jG1Drlw+y4JZT0gfxWElKf0TmVeJ1NjsqeRjNcpVthragud+jrWgK/dGdJaWVXAZqq98PPRcccEXhy0lbDY+pXnI97byu043PiT508IJPnnHY9rYXNgvJ4cOumyyc/BspmsUMP0P6LJOzfxTb3vWM1WWd7pg9gz9fB1lA7A0KMCoSwsOq9E+o54oxDoVX2abwoiYB7ZCuc/1i6KC0NXiB0/IiEM+lSajDSz/O01eocCugu/BKb9Q5tOCwofr/FQpqYWsvjq1/wPN3XMSLH6KjlcF3MvZv3USIRL+pW22OyMTOy21l36Q6zTz1YTNBPKCoW5Yz51/YIFa6CJAMEJxU0JSEUIu29IFMZogJtqV7wTnHmvKixoN8Il cXmSlJ3f 7SsY8nUhB+f40WduZAZYrNtBrHt1SjJpiJSiuKPHioonQ53FFx3EAu8ciof5RArUpf4B2uWfjQ94myUnNk2JWZgzHCbM8T1CnRVrZ42rc9Lz28kAQ+Ac87VPwyNp2hzw7gMSe9LKhj89plJ/ppbPKV6FTHlbZnUDPa2Q0MA60AP8bPO8/Nkg/CsZxxQyKbLYb4NioMbLD7AMYp1A= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 10/13/23 18:22, Kirill A. Shutemov wrote: > On Fri, Oct 13, 2023 at 03:33:58PM +0300, Kirill A. Shutemov wrote: >> > While testing SNP guests running today's tip/master (ef19bc9dddc3) I ran >> > into what seems to be fairly significant lock contention due to the >> > unaccepted_memory_lock spinlock above, which results in a constant stream >> > of soft-lockups until the workload gets all its memory accepted/faulted >> > in if the guest has around 16+ vCPUs. >> > >> > I've included the guest dmesg traces I was seeing below. >> > >> > In this case I was running a 32 vCPU guest with 200GB of memory running on >> > a 256 thread EPYC (Milan) system, and can trigger the above situation fairly >> > reliably by running the following workload in a freshly-booted guests: >> > >> > stress --vm 32 --vm-bytes 5G --vm-keep >> > >> > Scaling up the number of stress threads and vCPUs should make it easier >> > to reproduce. >> > >> > Other than unresponsiveness/lockup messages until the memory is accepted, >> > the guest seems to continue running fine, but for large guests where >> > unaccepted memory is more likely to be useful, it seems like it could be >> > an issue, especially when consider 100+ vCPU guests. >> >> Okay, sorry for delay. It took time to reproduce it with TDX. >> >> I will look what can be done. > > Could you check if the patch below helps? > > diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/efi/unaccepted_memory.c > index 853f7dc3c21d..591da3f368fa 100644 > --- a/drivers/firmware/efi/unaccepted_memory.c > +++ b/drivers/firmware/efi/unaccepted_memory.c > @@ -8,6 +8,14 @@ > /* Protects unaccepted memory bitmap */ > static DEFINE_SPINLOCK(unaccepted_memory_lock); > > +struct accept_range { > + struct list_head list; > + unsigned long start; > + unsigned long end; > +}; > + > +static LIST_HEAD(accepting_list); > + > /* > * accept_memory() -- Consult bitmap and accept the memory if needed. > * > @@ -24,6 +32,7 @@ void accept_memory(phys_addr_t start, phys_addr_t end) > { > struct efi_unaccepted_memory *unaccepted; > unsigned long range_start, range_end; > + struct accept_range range, *entry; > unsigned long flags; > u64 unit_size; > > @@ -80,7 +89,25 @@ void accept_memory(phys_addr_t start, phys_addr_t end) > > range_start = start / unit_size; > > + range.start = start; > + range.end = end; > +retry: > spin_lock_irqsave(&unaccepted_memory_lock, flags); > + > + list_for_each_entry(entry, &accepting_list, list) { > + if (entry->end < start) > + continue; > + if (entry->start > end) > + continue; > + spin_unlock_irqrestore(&unaccepted_memory_lock, flags); > + > + /* Somebody else accepting the range */ > + cpu_relax(); Should this be rather cond_resched()? I think cpu_relax() isn't enough to prevent soft lockups. Although IIUC hitting this should be rare, as the contending tasks will pick different ranges via try_to_accept_memory_one(), right? > + goto retry; > + } > + > + list_add(&range.list, &accepting_list); > + > for_each_set_bitrange_from(range_start, range_end, unaccepted->bitmap, > DIV_ROUND_UP(end, unit_size)) { > unsigned long phys_start, phys_end; > @@ -89,9 +116,15 @@ void accept_memory(phys_addr_t start, phys_addr_t end) > phys_start = range_start * unit_size + unaccepted->phys_base; > phys_end = range_end * unit_size + unaccepted->phys_base; > > + spin_unlock_irqrestore(&unaccepted_memory_lock, flags); > + > arch_accept_memory(phys_start, phys_end); > + > + spin_lock_irqsave(&unaccepted_memory_lock, flags); > bitmap_clear(unaccepted->bitmap, range_start, len); > } > + > + list_del(&range.list); > spin_unlock_irqrestore(&unaccepted_memory_lock, flags); > } >