Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp971333ybl; Fri, 30 Aug 2019 09:46:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTxMSQW1Y44C48c6t9SvaZVIb25w9A9FeU2hSFZ9/zT6h6XeBLVIEwpOn0uRgbuc5yP69v X-Received: by 2002:a63:6fc9:: with SMTP id k192mr13576306pgc.20.1567183594706; Fri, 30 Aug 2019 09:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567183594; cv=none; d=google.com; s=arc-20160816; b=LUGy8vncaLQmfIVaVjnjuGwRlaZZBUBXu0oMBUMOXEtMU+vSf8GogxqcqOaep1S/zZ jkQViKl/YKDquVIHke8Q4W1nxCvyeknCRtkmkysHqYBC16MAcdzXomr/Sn4p2m4P//0X lziylDdIg9irNXh4nEv06735OzMF+fOKjdq6GWQpDWIUAKKF0iLLq6jd3bDBPNRBhIVU b+n5LgR8K0t5qBKtPqYVqZfOXwGWXTfsdoe27/sW6lHogcWUT8xQHYpA2C+pA4WJRZdk IjU4PO90W/EBrt6GSizSG2cB4wR4bQSAy3ahngKwg9orEVCIhhprTS2cE/Hrv2kLn1Kn g2Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WMl6FqrCGGFKUtU/ehcmIWhYaPXfT9KQz+RU6G4D4NY=; b=HkUGvQHCKWMmfOsbEac7qKCHh+9CayKEmsJrqfZZo5jnWutAT2vzlYvyTAPnRneHWj eRxdCOLxiy3Dow3OjL/Q11QxKqNIC/fVjZu/zpmx8JBAHsWnO9QO8fDJQ02ZCVhtwxdp 3ZH7DKgerh+mGr8o97B5r+q16mOddEtxuCizzjsuLxgWHRohyME84uWBs7EDQ1UwaRFI mp6CJsDLb8suJru31WdIta0Pp+gC2OM0CslCE4+T8QDVlyRWrGo5Ru3+JWQ0/tppdzOj CjID4O+5ChHZCHpXQaEqDEe55tT+xy2njyx/vLwyzqW6ylxAzNk/S3H+Z9sZ2h58bBlX wIHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aeMzdkie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si5002731plr.52.2019.08.30.09.46.20; Fri, 30 Aug 2019 09:46:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aeMzdkie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728199AbfH3QpT (ORCPT + 99 others); Fri, 30 Aug 2019 12:45:19 -0400 Received: from mail.skyhub.de ([5.9.137.197]:37338 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727304AbfH3QpT (ORCPT ); Fri, 30 Aug 2019 12:45:19 -0400 Received: from zn.tnic (p200300EC2F0AAA00B4BCDAC90C3E20C3.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:aa00:b4bc:dac9:c3e:20c3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 85D001EC0959; Fri, 30 Aug 2019 18:45:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1567183517; h=from:from: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:in-reply-to:in-reply-to: references:references; bh=WMl6FqrCGGFKUtU/ehcmIWhYaPXfT9KQz+RU6G4D4NY=; b=aeMzdkieaJDnTF8lR/wP6brKjs1KZi6UM7ZApCw+MKJbcZ0PcETlALV41pmWxotKuakI7u j5KbDsbFtoIEZnjksPMDwGnYt/BfJPlpo3a/bavonsMhcJVQtGPO09rgIDp5PPivxL7S45 5Wjq13AwqXpZGikCRAhEAFKMRXnC2ig= Date: Fri, 30 Aug 2019 18:45:13 +0200 From: Borislav Petkov To: Kairui Song Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Thomas Lendacky , Baoquan He , Lianbo Jiang , Dave Young , x86@kernel.org, "kexec@lists.infradead.org" Subject: Re: [PATCH v2] x86/kdump: Reserve extra memory when SME or SEV is active Message-ID: <20190830164513.GE30413@zn.tnic> References: <20190826044535.9646-1-kasong@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190826044535.9646-1-kasong@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 26, 2019 at 12:45:35PM +0800, Kairui Song wrote: > Since commit c7753208a94c ("x86, swiotlb: Add memory encryption support"), > SWIOTLB will be enabled even if there is less than 4G of memory when SME > is active, to support DMA of devices that not support address with the > encrypt bit. > > And commit aba2d9a6385a ("iommu/amd: Do not disable SWIOTLB if SME is > active") make the kernel keep SWIOTLB enabled even if there is an IOMMU. > > Then commit d7b417fa08d1 ("x86/mm: Add DMA support for SEV memory > encryption") will always force SWIOTLB to be enabled when SEV is active > in all cases. > > Now, when either SME or SEV is active, SWIOTLB will be force enabled, > and this is also true for kdump kernel. As a result kdump kernel will > run out of already scarce pre-reserved memory easily. > > So when SME/SEV is active, reserve extra memory for SWIOTLB to ensure > kdump kernel have enough memory, except when "crashkernel=size[KMG],high" > is specified or any offset is used. As for the high reservation case, an > extra low memory region will always be reserved and that is enough for > SWIOTLB. Else if the offset format is used, user should be fully aware > of any possible kdump kernel memory requirement and have to organize the > memory usage carefully. > > Signed-off-by: Kairui Song > > --- > Update from V1: > - Use mem_encrypt_active() instead of "sme_active() || sev_active()" > - Don't reserve extra memory when ",high" or "@offset" is used, and > don't print redundant message. > - Fix coding style problem > > arch/x86/kernel/setup.c | 31 ++++++++++++++++++++++++++++--- > 1 file changed, 28 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > index bbe35bf879f5..221beb10c55d 100644 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -528,7 +528,7 @@ static int __init reserve_crashkernel_low(void) > > static void __init reserve_crashkernel(void) > { > - unsigned long long crash_size, crash_base, total_mem; > + unsigned long long crash_size, crash_base, total_mem, mem_enc_req; > bool high = false; > int ret; > > @@ -550,6 +550,15 @@ static void __init reserve_crashkernel(void) > return; > } > > + /* > + * When SME/SEV is active, it will always required an extra SWIOTLB > + * region. > + */ > + if (mem_encrypt_active()) > + mem_enc_req = ALIGN(swiotlb_size_or_default(), SZ_1M); > + else > + mem_enc_req = 0; Hmm, ugly. You set mem_enc_reg here ... > + > /* 0 means: find the address automatically */ > if (!crash_base) { > /* > @@ -563,11 +572,19 @@ static void __init reserve_crashkernel(void) > if (!high) > crash_base = memblock_find_in_range(CRASH_ALIGN, > CRASH_ADDR_LOW_MAX, > - crash_size, CRASH_ALIGN); > - if (!crash_base) > + crash_size + mem_enc_req, > + CRASH_ALIGN); > + /* > + * For high reservation, an extra low memory for SWIOTLB will > + * always be reserved later, so no need to reserve extra > + * memory for memory encryption case here. > + */ > + if (!crash_base) { > + mem_enc_req = 0; ... but you clear it here... > crash_base = memblock_find_in_range(CRASH_ALIGN, > CRASH_ADDR_HIGH_MAX, > crash_size, CRASH_ALIGN); > + } > if (!crash_base) { > pr_info("crashkernel reservation failed - No suitable area found.\n"); > return; > @@ -575,6 +592,7 @@ static void __init reserve_crashkernel(void) > } else { > unsigned long long start; > > + mem_enc_req = 0; ... and here... > start = memblock_find_in_range(crash_base, > crash_base + crash_size, > crash_size, 1 << 20); > @@ -583,6 +601,13 @@ static void __init reserve_crashkernel(void) > return; > } > } > + > + if (mem_enc_req) { > + pr_info("Memory encryption is active, crashkernel needs %ldMB extra memory\n", > + (unsigned long)(mem_enc_req >> 20)); > + crash_size += mem_enc_req; > + } ... and then you report only when it is still set. How about you carve out that if (!crash_base) { ... } else { } piece into a separate function without any further changes - only code movement? That is your patch 1. Your patch 2 is then adding the mem_encrypt_active() check in the if (!crash_base && !high) case, i.e., only where you need it and issuing the pr_info from there instead of stretching that logic throughout the whole function and twisting my brain unnecessarily? Thx. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.