Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp393990pxx; Wed, 28 Oct 2020 07:23:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMgIztI4HthgtK9lmE5GSJHTn6ZTe/5noLm2cnUVIIymBQkTSxVbXPIS3nTW1rQOidUY7F X-Received: by 2002:a17:906:31d0:: with SMTP id f16mr7557270ejf.409.1603894983711; Wed, 28 Oct 2020 07:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603894983; cv=none; d=google.com; s=arc-20160816; b=oWVn3MHIYFmOWN+ls8WGY/Vn15PsPXYaHhS78LNTLvq/VcS1In6UezG920d8C+Iih6 slfRmLH90PerB3cxa77Gwqn+aM7bW62cxJkTqEFmMb1CHPYchVx7broHApu1Pu10LB5l oh4S53h0f8H2hVsRj9hGMislDunzecdKoCsX4+YlZLl9CajDjFZ4hQiWGISzfjQLn3qW SUp8mw9paSvv0jg5Yniw4jRzx67P+zcn4HXMw2WWR/uoTJgDL5zUPRWE6fqUy3AKXdTg 4ZVw9GG4BH+8/6/z+eIl3EwIC80W8J+KHAj3IeoxGjqadAXAgCmvtcI2XYXX/F58KEWb zeIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QToMShd0BQlDxJvxtl6Te1FUPkRhaaJxDkmcgTjCchw=; b=miMoXEKLqq+nFHHDPflAmakq0VhxwkRLBWyadS+KMNpQ9QQ6wo7vhzYnBB+5lj797N Ap2e2Q+XU141Sh+JOCc3w2wjuj8B7gTgaofO0wdRgQaSDwjZUJ88IPMJdYfsp6auKy9D d6pxdj9P0h0Ak2OL7oJx93ldhAtxeNJ4HZlvfjyZlk07yV7td3AapAthmGGLJ8N8Ba5A Qrjrm8upApy7+Usgn7myph80a7QkQrG8vhnhOYOQ7+dLbsZGm0SoVTkKWxlC1o5700EH 7R2bcYhIXyXp4r077ZnjEipPoRithP54HvdT5T268g5ZVpsc+kEWwONUs6an80NfMUEw CqjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H+Yh+gwj; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o10si2705925ejr.482.2020.10.28.07.22.41; Wed, 28 Oct 2020 07:23:03 -0700 (PDT) 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=@kernel.org header.s=default header.b=H+Yh+gwj; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1805363AbgJ0QAs (ORCPT + 99 others); Tue, 27 Oct 2020 12:00:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:60014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1801342AbgJ0Pk0 (ORCPT ); Tue, 27 Oct 2020 11:40:26 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 036972231B; Tue, 27 Oct 2020 15:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813226; bh=ePINofZjEQeYPzMDeLIw73awv7lf8wrbC8bIrtPNMqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H+Yh+gwjSYseg549/cXGbmAFs6ULYTVgty3PdY6W5e8b4iAyBOc667IbOmBpynl0j zAPg1mkoo0DohJtHMokn99TXQ6fL9JqSvGmQ7e8UfaxXzDkc5q6JDCfxHdZQL+HV1G H1D2f2ikJ3m8AMxtq1l/LhKzfc1kUUhRtgCBaxJo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thiago Jung Bauermann , Konrad Rzeszutek Wilk , Michael Ellerman , Sasha Levin Subject: [PATCH 5.9 439/757] powerpc/pseries/svm: Allocate SWIOTLB buffer anywhere in memory Date: Tue, 27 Oct 2020 14:51:29 +0100 Message-Id: <20201027135511.134414310@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thiago Jung Bauermann [ Upstream commit eae9eec476d13fad9af6da1f44a054ee02b7b161 ] POWER secure guests (i.e., guests which use the Protected Execution Facility) need to use SWIOTLB to be able to do I/O with the hypervisor, but they don't need the SWIOTLB memory to be in low addresses since the hypervisor doesn't have any addressing limitation. This solves a SWIOTLB initialization problem we are seeing in secure guests with 128 GB of RAM: they are configured with 4 GB of crashkernel reserved memory, which leaves no space for SWIOTLB in low addresses. To do this, we use mostly the same code as swiotlb_init(), but allocate the buffer using memblock_alloc() instead of memblock_alloc_low(). Fixes: 2efbc58f157a ("powerpc/pseries/svm: Force SWIOTLB for secure guests") Signed-off-by: Thiago Jung Bauermann Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20200818221126.391073-1-bauerman@linux.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/svm.h | 4 ++++ arch/powerpc/mm/mem.c | 6 +++++- arch/powerpc/platforms/pseries/svm.c | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h index 85580b30aba48..7546402d796af 100644 --- a/arch/powerpc/include/asm/svm.h +++ b/arch/powerpc/include/asm/svm.h @@ -15,6 +15,8 @@ static inline bool is_secure_guest(void) return mfmsr() & MSR_S; } +void __init svm_swiotlb_init(void); + void dtl_cache_ctor(void *addr); #define get_dtl_cache_ctor() (is_secure_guest() ? dtl_cache_ctor : NULL) @@ -25,6 +27,8 @@ static inline bool is_secure_guest(void) return false; } +static inline void svm_swiotlb_init(void) {} + #define get_dtl_cache_ctor() NULL #endif /* CONFIG_PPC_SVM */ diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 42e25874f5a8f..ddc32cc1b6cfc 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -282,7 +283,10 @@ void __init mem_init(void) * back to to-down. */ memblock_set_bottom_up(true); - swiotlb_init(0); + if (is_secure_guest()) + svm_swiotlb_init(); + else + swiotlb_init(0); #endif high_memory = (void *) __va(max_low_pfn * PAGE_SIZE); diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c index e6d7a344d9f22..7b739cc7a8a93 100644 --- a/arch/powerpc/platforms/pseries/svm.c +++ b/arch/powerpc/platforms/pseries/svm.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -35,6 +36,31 @@ static int __init init_svm(void) } machine_early_initcall(pseries, init_svm); +/* + * Initialize SWIOTLB. Essentially the same as swiotlb_init(), except that it + * can allocate the buffer anywhere in memory. Since the hypervisor doesn't have + * any addressing limitation, we don't need to allocate it in low addresses. + */ +void __init svm_swiotlb_init(void) +{ + unsigned char *vstart; + unsigned long bytes, io_tlb_nslabs; + + io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT); + io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE); + + bytes = io_tlb_nslabs << IO_TLB_SHIFT; + + vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE); + if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false)) + return; + + if (io_tlb_start) + memblock_free_early(io_tlb_start, + PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT)); + panic("SVM: Cannot allocate SWIOTLB buffer"); +} + int set_memory_encrypted(unsigned long addr, int numpages) { if (!PAGE_ALIGNED(addr)) -- 2.25.1