Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2628172rdg; Mon, 16 Oct 2023 09:49:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdq6bULYFSOhEB05ud0o7oMkAxgQgCMZ0oa2O8s1or3t3ANh5JN1x/woLdE6ixU4jG1mnU X-Received: by 2002:a05:6a20:3d8b:b0:13d:2f80:cf1c with SMTP id s11-20020a056a203d8b00b0013d2f80cf1cmr34346155pzi.17.1697474975581; Mon, 16 Oct 2023 09:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474975; cv=none; d=google.com; s=arc-20160816; b=AUbggrhtmlEha9IBWBGBS9Lyn8CCotrrty6r9nAyMNv30Am9W5F+rQDutdqn+ToZkr xWZhbJdnMXPY+bUBGrT0P+FXZVH86uxEPRddOqtdI0dKTAXVFTx5FeoT3NOqD7oNgjf5 ZyhY36ZY6Gl6fF6jrPGCR19HOs59a+0+EShXA5VdbDJCaOIiz3Tgz+DOS1lMs6KbYEhj LZboKQ9oZz/ytf5Pt3Jo/LdpZE5ILPoABE5GfXf4+fvoDlrlNGACk+cu0U65kYC3FzDo zoTvNBmc+bkQJ9vUB9RJY2TW4giFQDPpHRLic2BZsQFH9eLrfZN1TQoDzNZCFVYqEM5I NeRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=GEefq32sBpLzJx2lGNyuxGH/nqJxW/5t5zmBcj5F6Ac=; fh=9XdDf3Vj29SCyPZzfTHo5JMX0RjqoRT8clOxELUZhU8=; b=GHxdWl6yGj8fe4O2EYBVh1PPF+N9PWPyfOypqYtTB/rB4L/zgeeBI0Ylf8uqcCwQ7g sSYsiNmcjUsNW+/tgzCn5DGaUZg6EBOhzHCf08BSBWqOUMu9VP5/GQPaRt/vexzT3hi2 ZtZA6hVDpy3jRnZynyLV+8MrxviI/obMKysQIkBOr1cjQ+AJ23tgkFyAWXfy6BfY7TTQ ywzj5pUGJxztuUBSM7J2uuS6ZVcUeCD7GRLyqyrTCenaUvKqOYPg3LbWUya/EV5yv0mk lQYZNyJyMdNlFU6DkydZwtUTLIaYPsua19y8e6/LTfY4JgKx89sxJROPEBATAxHepiEM 3VYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=l9WsDi6k; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=IywH00l9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id s26-20020a63925a000000b005ae4b7cdd6asi6985280pgn.284.2023.10.16.09.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:49:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=l9WsDi6k; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=IywH00l9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 07EF7807C868; Mon, 16 Oct 2023 09:49:33 -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 S233772AbjJPQtX (ORCPT + 99 others); Mon, 16 Oct 2023 12:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343664AbjJPQtM (ORCPT ); Mon, 16 Oct 2023 12:49:12 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A5510CC; Mon, 16 Oct 2023 09:41:05 -0700 (PDT) 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 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -3.65 X-Spamd-Result: default: False [-3.65 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-0.00)[20.47%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-2.99)[-0.997]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.56)[-0.563]; RCPT_COUNT_TWELVE(0.00)[32]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Status: No, score=-4.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS 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]); Mon, 16 Oct 2023 09:49:33 -0700 (PDT) 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); > } >