Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp925632rdg; Fri, 13 Oct 2023 05:34:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/mGq8eKHG+tu9QNzPHjHYDC9r6kMpDCEqLhruvpu1Ymjk0+ug3eC+lgWY41EYOhwG/pdU X-Received: by 2002:a05:6a21:7989:b0:171:a2df:4e68 with SMTP id bh9-20020a056a21798900b00171a2df4e68mr11542733pzc.36.1697200463815; Fri, 13 Oct 2023 05:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697200463; cv=none; d=google.com; s=arc-20160816; b=UNuc4Fhel2JXViwpWZmq0wDOy2YSeWlunAK1EtE8K4TRXdLBeTzP0Yag9oEoqrOceo MYph2IgGXkWvhlO9o1zHQXBAzV8dsyxzINDv50ijuIqdTo1R6qyjhVIz8bLmKEYHyal0 CXgyr2lRjXan57QU6n8nh/NRFb6GV/KI+v+t8PIIyMwJe5vvTwX9lwb+grijudSJ5g7l W1+conF22MfvWDzPRXuoGnhTKMrInPKnVWIjJ5OGtMXVFLNNhlO6OaUpMR3ntS8M8qdX TNa6JfNvyU4jhRqkga8FAvPFx8vFEPsCSg02EvIvQJ9owbBXjVInJzdckw0Y5JApU/oz m0kA== 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=uYtmUhmwaaBTNa8kFVOzNzwocrXdB8aiXoGdyFWTayk=; fh=A/A3doFx38e4Hd+WLWSmVt1Seq4l3+ofTRGOxZp/LM4=; b=LE5K7dG4F7pcuME4gOVv76J7iE7N9OQck1dyx5GIZCruOH8a1zzTARC3G25ZNkZKY8 0Ths6CUoDcryLMyjkPgTXH/xgiEV+bFtk5VETOoG6aM+2T5x9o1zABYN/XFsHVLu9Qsh xSX2JR4vkx/J1MZA2TrrjH6a5Yoq+VfZnWLzqeq3D2jpPqN76TLRwAQAAHZEijTdeEB7 wi0+WJ4CbnMtw9oUWB/8qJy859FVFXscLr7JQEZkcMb8eHJNH4vIBTJtYsrs38Jl2hre 733QYCuleZO87tjgJ9pnWdfuOkLlvH+mtR1qaWqjGoRM8ucxWcCa8IxIAcIGch8mn+Rp GHxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E+4Trx1l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id ca39-20020a056a0206a700b005ae22729b09si395586pgb.683.2023.10.13.05.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:34:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E+4Trx1l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id C680E81DDBDE; Fri, 13 Oct 2023 05:34:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231686AbjJMMeN (ORCPT + 99 others); Fri, 13 Oct 2023 08:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbjJMMeM (ORCPT ); Fri, 13 Oct 2023 08:34:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 380C0A9; Fri, 13 Oct 2023 05:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697200451; x=1728736451; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=fGrVnxZmpyfEBqkF7piZXz/mFn6UmaNoaPJzfrOU+hs=; b=E+4Trx1lgbtY2WHWLk0Je/JAxFjCBhMJkmdjRYB2JGESbNg6x59KgsI+ 851mgsfnjJDOyXD0qAIajccM57rSJCwzDwjaJuBcX09WJpNXoF7jP9uMz xErR1cHhXEk+GCcuSqqUjEohLfsrt3wP4YyZNENFHTQ5FkkIZGYTsQkW5 jUxSSWQFuNvUXNvO4Vk/iiDpoGm66lNRN1n2dgJrxtwP3bfVGaIQL3sJh W3N6YHu7S6l7rhgbRShHw0/MUugjWGmStAqY0L75X6g6duOVFbpCL8S+y LtgF7Tl3fkFB5Ih6vLntzsjNuv7xCUEaIVIlKWeRkk0yBfdhqArNostPJ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="364536435" X-IronPort-AV: E=Sophos;i="6.03,222,1694761200"; d="scan'208";a="364536435" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 05:34:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10862"; a="1086128325" X-IronPort-AV: E=Sophos;i="6.03,222,1694761200"; d="scan'208";a="1086128325" Received: from bgras-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.59.145]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2023 05:34:01 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 6E30C104A05; Fri, 13 Oct 2023 15:33:58 +0300 (+03) Date: Fri, 13 Oct 2023 15:33:58 +0300 From: "Kirill A. Shutemov" To: Michael Roth Cc: Borislav Petkov , Andy Lutomirski , Dave Hansen , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel , Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , 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 Subject: Re: [PATCHv14 5/9] efi: Add unaccepted memory support Message-ID: <20231013123358.y4pcdp5fgtt4ax6g@box.shutemov.name> References: <20230606142637.5171-1-kirill.shutemov@linux.intel.com> <20230606142637.5171-6-kirill.shutemov@linux.intel.com> <20231010210518.jguawj7bscwgvszv@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231010210518.jguawj7bscwgvszv@amd.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 13 Oct 2023 05:34:20 -0700 (PDT) On Tue, Oct 10, 2023 at 04:05:18PM -0500, Michael Roth wrote: > On Tue, Jun 06, 2023 at 05:26:33PM +0300, Kirill A. Shutemov wrote: > > efi_config_parse_tables() reserves memory that holds unaccepted memory > > configuration table so it won't be reused by page allocator. > > > > Core-mm requires few helpers to support unaccepted memory: > > > > - accept_memory() checks the range of addresses against the bitmap and > > accept memory if needed. > > > > - range_contains_unaccepted_memory() checks if anything within the > > range requires acceptance. > > > > Architectural code has to provide efi_get_unaccepted_table() that > > returns pointer to the unaccepted memory configuration table. > > > > arch_accept_memory() handles arch-specific part of memory acceptance. > > > > Signed-off-by: Kirill A. Shutemov > > Reviewed-by: Ard Biesheuvel > > Reviewed-by: Tom Lendacky > > --- > > arch/x86/platform/efi/efi.c | 3 + > > drivers/firmware/efi/Makefile | 1 + > > drivers/firmware/efi/efi.c | 25 +++++ > > drivers/firmware/efi/unaccepted_memory.c | 112 +++++++++++++++++++++++ > > include/linux/efi.h | 1 + > > 5 files changed, 142 insertions(+) > > create mode 100644 drivers/firmware/efi/unaccepted_memory.c > > > > diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/efi/unaccepted_memory.c > > new file mode 100644 > > index 000000000000..08a9a843550a > > --- /dev/null > > +++ b/drivers/firmware/efi/unaccepted_memory.c > > @@ -0,0 +1,112 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > + > > +#include > > +#include > > +#include > > +#include > > + > > +/* Protects unaccepted memory bitmap */ > > +static DEFINE_SPINLOCK(unaccepted_memory_lock); > > + > > +/* > > + * accept_memory() -- Consult bitmap and accept the memory if needed. > > + * > > + * Only memory that is explicitly marked as unaccepted in the bitmap requires > > + * an action. All the remaining memory is implicitly accepted and doesn't need > > + * acceptance. > > + * > > + * No need to accept: > > + * - anything if the system has no unaccepted table; > > + * - memory that is below phys_base; > > + * - memory that is above the memory that addressable by the bitmap; > > + */ > > +void accept_memory(phys_addr_t start, phys_addr_t end) > > +{ > > + struct efi_unaccepted_memory *unaccepted; > > + unsigned long range_start, range_end; > > + unsigned long flags; > > + u64 unit_size; > > + > > + unaccepted = efi_get_unaccepted_table(); > > + if (!unaccepted) > > + return; > > + > > + unit_size = unaccepted->unit_size; > > + > > + /* > > + * Only care for the part of the range that is represented > > + * in the bitmap. > > + */ > > + if (start < unaccepted->phys_base) > > + start = unaccepted->phys_base; > > + if (end < unaccepted->phys_base) > > + return; > > + > > + /* Translate to offsets from the beginning of the bitmap */ > > + start -= unaccepted->phys_base; > > + end -= unaccepted->phys_base; > > + > > + /* Make sure not to overrun the bitmap */ > > + if (end > unaccepted->size * unit_size * BITS_PER_BYTE) > > + end = unaccepted->size * unit_size * BITS_PER_BYTE; > > + > > + range_start = start / unit_size; > > + > > + spin_lock_irqsave(&unaccepted_memory_lock, flags); > > + for_each_set_bitrange_from(range_start, range_end, unaccepted->bitmap, > > + DIV_ROUND_UP(end, unit_size)) { > > + 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; > > + > > + arch_accept_memory(phys_start, phys_end); > > + bitmap_clear(unaccepted->bitmap, range_start, len); > > + } > > + spin_unlock_irqrestore(&unaccepted_memory_lock, flags); > > +} > > 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. -- Kiryl Shutsemau / Kirill A. Shutemov