Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp43396pxa; Tue, 18 Aug 2020 15:17:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJc5Wm09WINfnReQ4nWF3sX+jEUEmI/g7H5yHym4YboC61VcFH3RGcag+r4uIyYxqFv8rE X-Received: by 2002:a17:906:86c9:: with SMTP id j9mr21838655ejy.5.1597789064166; Tue, 18 Aug 2020 15:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597789064; cv=none; d=google.com; s=arc-20160816; b=zzwrsql2zUP83qhLnpTqxgLqWc2rCRQCmqMNovk8P/EWY/Z2kxa10PqBjECGk4EL/1 aI7bmuyTk3XoQDK7pzLU8oFWSTqWGXfVMqhMzROZDlBBnsQgI8ZlKyXDvIfHb3zXD8pZ uO2FZtKpHojEFsoz6ltMcXO79+os7ajy1+1aElhoHX5ZlNM6BP0ECx9xscmsgAJYgJ2U Cu0xl6Ygd4iYpCTeIYQLDYGyzIGDJV3GAw9gqHbvjP/6gbv4/lRc0km+XyH4Lsv9Veiq ZojE8ZHOMfwHleL4AlWsuPzB+wdA3bKc4WTCrHFDzgW7Ua1HPuLcqtUHaO62xpK3NN3O CMzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UtNXnoPsOjscFTkbhxjmseTZ2dxM8ncEn7IWYIO6opA=; b=bzrnludCMNZWK40OvYbOy7DzRbRBX6OEAIh91tAUuwNKmf8s3nW41fzkqhRovei2aT Vv7Si88Ivw1NwigPJmwgbVFnzQLukIKrp7wvhB/7eUPkYxbxhwI1MGD870JiMed3eU+7 Kbspo47zvE3K+xOLdGbkRnkWzKK+MOkIv1JqAb3JeE2sx2uWpHXiF6Ef/4ySNUNcWiAp vi8yYHR/H22YIeQcZcLW4eMGNCRcU/EM6dIc+lx212r3nURDTZ10k+g+XFyr8sN+535g hJWFZaAhF84eGwKW9jepYMGTZ5lCf9tg8nmINv+tnMEQKaMknxf0sWLW8zyGqlMtiW4p wKtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=sGIsWT+S; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb11si13804263edb.344.2020.08.18.15.17.18; Tue, 18 Aug 2020 15:17:44 -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=@ibm.com header.s=pp1 header.b=sGIsWT+S; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726919AbgHRWMY (ORCPT + 99 others); Tue, 18 Aug 2020 18:12:24 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:62950 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726617AbgHRWMW (ORCPT ); Tue, 18 Aug 2020 18:12:22 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07IM2e6M117975; Tue, 18 Aug 2020 18:11:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=UtNXnoPsOjscFTkbhxjmseTZ2dxM8ncEn7IWYIO6opA=; b=sGIsWT+SExHnhfEnQnakW67QRlkpHGIfcjEMPTTVOXyEMXSIEADQ/GmXm9WqSnHBE3ma 125fHGQJW34u+Hq2LJxWvejczl2IEbrljzRuFt7/VNKn4Xw4m8tk3OA9L0Xk7AZlj4Im TA7j1aZZDcXiAaYidNxlsDsQnNGZGcR3/yIYmh2PkDW6Ur+qhPrrYJd5cLAHEGqlsU0B UbjRdIQRD1RknQVJoPN56lXxy8uPuWwcyCXtWDMzFQWWcVLeh+kpodhnUWpeT+Uvr2ku IV67nkX4Z+BOKnJxFsiKEhtWDlEX794yZqzkohsCPa7TQKdaEE1s5+DHnn5EXyXTSbki yA== Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com with ESMTP id 3304t20phf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Aug 2020 18:11:43 -0400 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07IM9Yue019412; Tue, 18 Aug 2020 22:11:43 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma02dal.us.ibm.com with ESMTP id 3304cch4sc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Aug 2020 22:11:43 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07IMBbJa19398974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Aug 2020 22:11:37 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 69A38C607D; Tue, 18 Aug 2020 22:11:40 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E94C7C6087; Tue, 18 Aug 2020 22:11:37 +0000 (GMT) Received: from morokweng.localdomain.com (unknown [9.163.41.251]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 18 Aug 2020 22:11:37 +0000 (GMT) From: Thiago Jung Bauermann To: iommu@lists.linux-foundation.org Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Konrad Rzeszutek Wilk , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Michael Ellerman , Ram Pai , Satheesh Rajendran , Thiago Jung Bauermann Subject: [PATCH v3] powerpc/pseries/svm: Allocate SWIOTLB buffer anywhere in memory Date: Tue, 18 Aug 2020 19:11:26 -0300 Message-Id: <20200818221126.391073-1-bauerman@linux.ibm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-18_14:2020-08-18,2020-08-18 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 suspectscore=3 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008180154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org POWER secure guests (i.e., guests which use the Protection 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(). Signed-off-by: Thiago Jung Bauermann --- 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(-) Changes from v2: - Panic if unable to allocate buffer, as suggested by Christoph. Changes from v1: - Open-code swiotlb_init() in arch-specific code, as suggested by Christoph. diff --git a/arch/powerpc/include/asm/svm.h b/arch/powerpc/include/asm/svm.h index 85580b30aba4..7546402d796a 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 c2c11eb8dcfc..0f21bcb16405 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -290,7 +291,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 40c0637203d5..81085eb8f225 100644 --- a/arch/powerpc/platforms/pseries/svm.c +++ b/arch/powerpc/platforms/pseries/svm.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -34,6 +35,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))