Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1000755pxu; Mon, 23 Nov 2020 09:10:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKHJx5l87WHpI02XO+xOTJC2rcltB4S0GbS+dJ0GQNvNGH7agfISWtewKM8iZoNPhlL+uO X-Received: by 2002:a17:906:57ca:: with SMTP id u10mr513863ejr.389.1606151433320; Mon, 23 Nov 2020 09:10:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606151433; cv=none; d=google.com; s=arc-20160816; b=i7OMc6hIILyL9lfB17skVb2orx1Ob1/YyrxSbY5krK7pp4beOgAZt5UxVmJkRZE3fk KUJnXVaYqQ6VPQOSgEP5EyM5lag8wPq+P+ByMVy/t50UQHxWXlmip9vH/H1TGwmnEXPI 1+9G3qnlS4k36aBGLb/J4VmO+rNdFl/LoguUdzwMpjVd8lq32TSQiHCjZKfK+So0Xytv rzCf6/+KALiNRhuHDzzyi0dSPzwO1V44BfCdIbfg4Jpdu2ic2WarGDZVNv2cJ0WO3EfV 2nl9pnrwi6yRWsbuKpohe0MNa6e/gOtY74O8qoboBSsrRdTrHLsXFJLXUIM0V2kXW34L Fq6g== 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=XCdr223yFPf0fIu1JE5bbRlc9o/DCKzzYdZoouood6g=; b=oNZB7KHFUwZQLx/EGp+8d5i6tjRUWJQjAa6BfxkOzlyjSi0uInYJSpvG7zbs7rpluS Y2nDtfelTAdlHryU2cbFusCpEGAhqdSN4ODSi7JZDG2mFmUebbADm8M1mJYQJ9y5qMmN h2KFTtreh9MQHmqhLvuMj65tyWyAJ3nf1EKmN+a9QLxL0dKulT8nndbkgJdRFNmEQQ42 81lTm2DJXEblvNdAlyb2HjheKYi/TXpnphqDlZoAZZxHesui8vSH7jVFrvXjzM377PX9 Api7RMuWKqXEAKbkvrwzHr6koDeMSQyLVQ2sSFG69X0mT1nXFOwLKTxqsf+OSEXKebeX f3UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=peGB592K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id p1si7343589edb.422.2020.11.23.09.10.08; Mon, 23 Nov 2020 09:10:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=peGB592K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2390297AbgKWRGz (ORCPT + 99 others); Mon, 23 Nov 2020 12:06:55 -0500 Received: from mail.skyhub.de ([5.9.137.197]:43806 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390295AbgKWRGy (ORCPT ); Mon, 23 Nov 2020 12:06:54 -0500 Received: from zn.tnic (p200300ec2f0bbc0000a4f4bc59f4c3b0.dip0.t-ipconnect.de [IPv6:2003:ec:2f0b:bc00:a4:f4bc:59f4:c3b0]) (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 3A19A1EC0453; Mon, 23 Nov 2020 18:06:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1606151213; 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=XCdr223yFPf0fIu1JE5bbRlc9o/DCKzzYdZoouood6g=; b=peGB592Kii+J5hllpaKDM+2d6k8bvzKbro3E7pgl9EMNtkCnTPdytqULIcto1VCYCE40H2 iqwYUAA925pWMBjIcRNXMxCJ9bGyIjZ5oHpB9mgr+wDxZNRCbEjuhgJRhQZF2Vv13R+q6m fTQzmmgIYgQvYEuhHoeqEyI5hD2dfM8= Date: Mon, 23 Nov 2020 18:06:47 +0100 From: Borislav Petkov To: Ashish Kalra Cc: konrad.wilk@oracle.com, hch@lst.de, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, luto@kernel.org, peterz@infradead.org, dave.hansen@linux-intel.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, brijesh.singh@amd.com, Thomas.Lendacky@amd.com, jon.grimm@amd.com, rientjes@google.com Subject: Re: [PATCH v6] swiotlb: Adjust SWIOTBL bounce buffer size for SEV guests. Message-ID: <20201123170647.GE15044@zn.tnic> References: <20201119214205.11062-1-Ashish.Kalra@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201119214205.11062-1-Ashish.Kalra@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 09:42:05PM +0000, Ashish Kalra wrote: > From: Ashish Kalra > > For SEV, all DMA to and from guest has to use shared (un-encrypted) pages. > SEV uses SWIOTLB to make this happen without requiring changes to device > drivers. However, depending on workload being run, the default 64MB of > SWIOTLB might not be enough and SWIOTLB may run out of buffers to use > for DMA, resulting in I/O errors and/or performance degradation for > high I/O workloads. > > Increase the default size of SWIOTLB for SEV guests using a minimum > value of 128MB and a maximum value of 512MB, determining on amount > of provisioned guest memory. That sentence needs massaging. > Using late_initcall() interface to invoke swiotlb_adjust() does not > work as the size adjustment needs to be done before mem_encrypt_init() > and reserve_crashkernel() which use the allocated SWIOTLB buffer size, > hence calling it explicitly from setup_arch(). "hence call it ... " > > The SWIOTLB default size adjustment is added as an architecture specific "... is added... " needs to be "Add ..." > interface/callback to allow architectures such as those supporting memory > encryption to adjust/expand SWIOTLB size for their use. > > v5 fixed build errors and warnings as > Reported-by: kbuild test robot > > Signed-off-by: Ashish Kalra > --- > arch/x86/kernel/setup.c | 2 ++ > arch/x86/mm/mem_encrypt.c | 32 ++++++++++++++++++++++++++++++++ > include/linux/swiotlb.h | 6 ++++++ > kernel/dma/swiotlb.c | 24 ++++++++++++++++++++++++ > 4 files changed, 64 insertions(+) > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > index 3511736fbc74..b073d58dd4a3 100644 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -1166,6 +1166,8 @@ void __init setup_arch(char **cmdline_p) > if (boot_cpu_has(X86_FEATURE_GBPAGES)) > hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT); > > + swiotlb_adjust(); > + > /* > * Reserve memory for crash kernel after SRAT is parsed so that it > * won't consume hotpluggable memory. > diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c > index 3f248f0d0e07..c79a0d761db5 100644 > --- a/arch/x86/mm/mem_encrypt.c > +++ b/arch/x86/mm/mem_encrypt.c > @@ -490,6 +490,38 @@ static void print_mem_encrypt_feature_info(void) > } > > /* Architecture __weak replacement functions */ > +unsigned long __init arch_swiotlb_adjust(unsigned long iotlb_default_size) > +{ > + unsigned long size = 0; unsigned long size = iotlb_default_size; > + > + /* > + * For SEV, all DMA has to occur via shared/unencrypted pages. > + * SEV uses SWOTLB to make this happen without changing device > + * drivers. However, depending on the workload being run, the > + * default 64MB of SWIOTLB may not be enough & SWIOTLB may ^ Use words pls, not "&". > + * run out of buffers for DMA, resulting in I/O errors and/or > + * performance degradation especially with high I/O workloads. > + * Increase the default size of SWIOTLB for SEV guests using > + * a minimum value of 128MB and a maximum value of 512MB, > + * depending on amount of provisioned guest memory. > + */ > + if (sev_active()) { > + phys_addr_t total_mem = memblock_phys_mem_size(); > + > + if (total_mem <= SZ_1G) > + size = max(iotlb_default_size, (unsigned long) SZ_128M); > + else if (total_mem <= SZ_4G) > + size = max(iotlb_default_size, (unsigned long) SZ_256M); > + else > + size = max(iotlb_default_size, (unsigned long) SZ_512M); > + > + pr_info("SWIOTLB bounce buffer size adjusted to %luMB for SEV platform", just "... for SEV" - no need for "platform". ... > diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c > index c19379fabd20..3be9a19ea0a5 100644 > --- a/kernel/dma/swiotlb.c > +++ b/kernel/dma/swiotlb.c > @@ -163,6 +163,30 @@ unsigned long swiotlb_size_or_default(void) > return size ? size : (IO_TLB_DEFAULT_SIZE); > } > > +unsigned long __init __weak arch_swiotlb_adjust(unsigned long size) > +{ > + return 0; That, of course, needs to return size, not 0. > +} > + > +void __init swiotlb_adjust(void) > +{ > + unsigned long size; > + > + /* > + * If swiotlb parameter has not been specified, give a chance to > + * architectures such as those supporting memory encryption to > + * adjust/expand SWIOTLB size for their use. > + */ And when you preset the function-local argument "size" with the size coming in as the size argument of arch_swiotlb_adjust()... > + if (!io_tlb_nslabs) { > + size = arch_swiotlb_adjust(IO_TLB_DEFAULT_SIZE); > + if (size) { ... you don't have to do if (size) here either but simply use size to compute io_tlb_nslabs, I'd say. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette