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 E12AACDB465 for ; Mon, 16 Oct 2023 16:41:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3578A8E0009; Mon, 16 Oct 2023 12:41:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3078B8D0001; Mon, 16 Oct 2023 12:41:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CEBC8E0009; Mon, 16 Oct 2023 12:41:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0B9EA8D0001 for ; Mon, 16 Oct 2023 12:41:10 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C93CBC0998 for ; Mon, 16 Oct 2023 16:41:09 +0000 (UTC) X-FDA: 81351889458.05.3E25A2F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf22.hostedemail.com (Postfix) with ESMTP id 5525BC001A for ; Mon, 16 Oct 2023 16:41:06 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=l9WsDi6k; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=IywH00l9; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697474466; a=rsa-sha256; cv=none; b=dA9aT3PICRV4wKvSYzSyuU4+V4OskdvWzh1pPox8asd/OUdfq713I4Hppaznr99Fgxm5EK 7EMDt9QhK7xlPvqebVGtxPKdbewPHrsXK97hMhtV2RzfKAtHtCS4mqEIF09zXY+iii8WiJ AQEC5FEwabt+Ux63B5jAhcRZzS5XYtE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=l9WsDi6k; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=IywH00l9; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 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=1697474466; 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=GEefq32sBpLzJx2lGNyuxGH/nqJxW/5t5zmBcj5F6Ac=; b=hlRzSqU5i3ERo75Sdmkr4bBbusOGmNcdUccQxjVMXQRsD3VHAjxd+z2dhnp1IcLVmCgh6h hlQyMjVZRXw1J25Wp+DCVg8ygmhlQWN78t7C0zQCVr0JSmdmQKIsNUBbjCdx64RlNWdONu 9WhuG1mjww/HlU2hJlTgoeioYS3yT9Q= 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-out2.suse.de (Postfix) with ESMTPS id 017C51FEC1; Mon, 16 Oct 2023 16:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1697474464; 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=GEefq32sBpLzJx2lGNyuxGH/nqJxW/5t5zmBcj5F6Ac=; b=l9WsDi6kmvu6IvcoWBYG976vX4FGtLkDTLqQzCItBRi/1ekOptrfqe2NByqKfSndcdsKl7 5Sb3g4KaZgOC5i/oLNKXKSc5i/lc4cT9pj2/2EYNM+bTX59iiXaQKhPaGAXnV8LssgqShL fvpYgCyWJ4r+jtAci6jwRDmCzyKufpQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1697474464; 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=GEefq32sBpLzJx2lGNyuxGH/nqJxW/5t5zmBcj5F6Ac=; b=IywH00l91MbjWq7du2aCvwlTuYrCsljv8qEifxJMZRpyDI36lSOQDXKGwVshOVggkqnMYs PvImr/h4iRaXh/Bw== 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 6D5BF133B7; Mon, 16 Oct 2023 16:41:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AyLMGZ9nLWXEKgAAMHmgww (envelope-from ); Mon, 16 Oct 2023 16:41:03 +0000 Message-ID: <5d4eda63-d479-bf4a-7bfb-98a7fb8f953d@suse.cz> Date: Mon, 16 Oct 2023 18:41:02 +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: [PATCHv2] efi/unaccepted: Fix soft lockups caused by parallel memory acceptance To: "Kirill A. Shutemov" , Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: 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 References: <20231016163122.12855-1-kirill.shutemov@linux.intel.com> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20231016163122.12855-1-kirill.shutemov@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5525BC001A X-Stat-Signature: f94duxpnjw64bh1sqzw8ni6cb5s3o7ja X-Rspam-User: X-HE-Tag: 1697474466-829462 X-HE-Meta: U2FsdGVkX18JiLf4CV9Ixph0GCH234Ur6Ji7n5tbFcnFH3i5QfYi98UA1wySt24SOQWL+wcE3KI7/fthencns4BIwgFMM/gpghKE/qF65IXWnIP/YGqpNCsj8vcnhl8kmgIuAaxByy0+EMsUoFtdbOogfRFYLtydQe0o/YArNHuyS4a79y7xTQHAqhy6yIcE0aJMgZkXpBU7Rw73zPMeBr9ZsnlEPB10oi1mE5f+O7Z3pp1hTatZe2Pti+ff6q6dBeAGy/PzE96DC7wg8ZCyPiofKthwW44LkBMx+FnHuOiV95RkeV2Vdpoknv9bs3iZr0t2MT3F9oc2A30BomrctpWRDu4EIBSNPro5HLSrH4NIXMoBadrk75vL64N74MIDANPJG9cgckkuWNMPp/S6ezBqcauRx/Xh2P29ZGdlJD93ZqzA/HjUnfTBr04d8hyNMYM2C3S9WlmtMpBlfzXxVkbAZHeEtX63JgzL/Fmel5A0vqG7UaDjVGK4eDvbFksYgVWkqMq24QjxrLj1nTwoIWkqwK65iuKXRCPHG5iFdMiDVjMHajCl9Rar8OG82c/edJFnczrmU5lrQo7SJeuvS8uFiLQLhtbg79w2bN40ibRGaSO+cuyadpMRuL9ldxc/R/yuDzVAFnb6RBpEwLv0AYkWZL1+yxtHBljnT1D6xyEaHFNo4nHwNsTobasgY0iXjvZA1DnW9h8xt+bxdZzRGoiysBIaozNrlHuF6rjnKOvJRB4z+eOmoSHGvPdrzEb/yIemfpwUljjJ/6eJSugd8KXUM+Wxe+WKCqXYhX9N7Qn3Ob68Px6QsDlZ7mpgHV/N2HpEEHuXbiPXECIO/M0axZvncbne5BIShJn7eNieIPZ38wrG1f4sreNjAoL7Wwn47NQmW8owyh9Ss8HRpfnnPph7qJlfEbhNU2C3+Y0SqdQv8MVRSS7rOcH8jmFIZ9WIW9X7ZHYoy8SFIs24CnR dHLTC+09 LFb6Hzw2WfOcT/aqAD1Jodfw8vcY/o1rvDpws4ns1rH/3ahMOeZLkm4KNSl6/nEVZBMjlJNtTr1zaf4Fk+X4gUAlkyXq5cSwFDEPjcedL1DMHpeyGeo6Y4FREwbnyg5WJeuS8+qEWxiy2HRGYtNa5cCjVucN9NwAvvTz1SqmyJ667ve8/jw6xNxtWUhaTDwDJXt4X9Ao745ckacg0UdJ9vx3hsSzbSkPNfoPZn2PCIAgzFZRd7bpur1SU1gGLWih6vv4qwoHBDXXhTQSAJzXKy7ou792YF1sFq6veZctMvX5T9Oh8b/XuxGweh/P9vJpDcW8CQBbpBfLoO4cswFee99YccAsABgOP54hnj5NpIfucweM= 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/16/23 18:31, Kirill A. Shutemov wrote: > Michael reported soft lockups on a system that has unaccepted memory. > This occurs when a user attempts to allocate and accept memory on > multiple CPUs simultaneously. > > The root cause of the issue is that memory acceptance is serialized with > a spinlock, allowing only one CPU to accept memory at a time. The other > CPUs spin and wait for their turn, leading to starvation and soft lockup > reports. > > To address this, the code has been modified to release the spinlock > while accepting memory. This allows for parallel memory acceptance on > multiple CPUs. > > A newly introduced "accepting_list" keeps track of which memory is > currently being accepted. This is necessary to prevent parallel > acceptance of the same memory block. If a collision occurs, the lock is > released and the process is retried. > > Such collisions should rarely occur. The main path for memory acceptance > is the page allocator, which accepts memory in MAX_ORDER chunks. As long > as MAX_ORDER is equal to or larger than the unit_size, collisions will > never occur because the caller fully owns the memory block being > accepted. > > Aside from the page allocator, only memblock and deferered_free_range() > accept memory, but this only happens during boot. > > The code has been tested with unit_size == 128MiB to trigger collisions > and validate the retry codepath. > > Signed-off-by: Kirill A. Shutemov > Reported-by: Michael Roth Fixes: 2053bc57f367 ("efi: Add unaccepted memory support") > Cc: > Reviewed-by: Nikolay Borisov Reviewed-by: Vlastimil Babka > + range_start = range.start; > for_each_set_bitrange_from(range_start, range_end, unaccepted->bitmap, > - DIV_ROUND_UP(end, unit_size)) { > + range.end) { > unsigned long phys_start, phys_end; > unsigned long len = range_end - range_start; > > phys_start = range_start * unit_size + unaccepted->phys_base; > phys_end = range_end * unit_size + unaccepted->phys_base; > > + /* > + * Keep interrupts disabled until the accept operation is > + * complete in order to prevent deadlocks. > + * > + * Enabling interrupts before calling arch_accept_memory() > + * creates an opportunity for an interrupt handler to request > + * acceptance for the same memory. The handler will continuously > + * spin with interrupts disabled, preventing other task from > + * making progress with the acceptance process. > + */ AFAIU on PREEMPT_RT the spin_lock_irqsave() doesn't disable interrupts, so this does not leave them disabled. But it also shouldn't be a risk of deadlock because the interrupt handlers are themselves preemptible. The latency might be bad as the cpu_relax() retry loop will not cause the task everyone might be waiting for to be prioritised, but I guess it's not a big issue as anyone with RT requirements probably won't use unaccepted memory in the first place, and as you mention hitting the retry loop after boot in a normal configuration should be pretty much never. > + spin_unlock(&unaccepted_memory_lock); > + > arch_accept_memory(phys_start, phys_end); > + > + spin_lock(&unaccepted_memory_lock); > bitmap_clear(unaccepted->bitmap, range_start, len); > } > + > + list_del(&range.list); > spin_unlock_irqrestore(&unaccepted_memory_lock, flags); > } >