Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3039683imm; Fri, 24 Aug 2018 09:28:40 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda6eY5mI6T08eBBGlHzn5A7afhb/oYSSNVg4R8iVCF/mJqW5yfl61AcehncGCaBhAZ8ThAJ X-Received: by 2002:a63:d04f:: with SMTP id s15-v6mr2403711pgi.42.1535128120171; Fri, 24 Aug 2018 09:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535128120; cv=none; d=google.com; s=arc-20160816; b=Ld87GZ7rLETrXYjl6+7EfVrr4Ymw2Q1iPQUSeXxK0KAQP86NlKdMLiu1Yfbi0jwGuG nIWCjk+34M91Br1qpt9/05c6Rh7a9Q4n49KV9EuHYTNx4aT6gdcHGMLjPsOrcXluJjXl kaKj0GT5nCWaP3s6yDR9qlqqlkusBH2fhrcF/YpCJQByNiKjeAHKE8WRIrwlzScEiSyW szhGIrKfcjiWtugKhG/TdFFBQVEg0JXTSqNPT4zRPt302mH6HPAbX0FWsJV7p3SJduXG kDlH7RB2QZyfvWG7UtfE65ZDig08x3tXxRxA+Woxk7jPVA96WnNROSj4IcUYP7Mtc3HF oCRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=PaUKhj+Mt+n8aeKWaoPgpnrr5sajYYVGcDGb8rsorAI=; b=mBVfC/5eWamkAaT7bEOQM75vxX+OeDn9A2hklqBRSywqmcnaSHybfnZHsOe4o+EmcF AyCs1yeE0T0N5B6NG0ok6zY2sOGr3yjNOJpolxKqLhgWmxhVpLvbOij+NcXrRpOAIM8b cMWPn9HbFiC4yw26BX35lFpSkBsVU97yR6HsiDgW1o8OmP2uvtkMDSxsBUm/z7DuOB1d BYoGfU3LuYktzPo0Zdv1mNnHF8DyH0+OAycogRrpIDXHKKOjHe7IXrfzN7LgMJX+Tsid V+TeM6/KHXqac6c+ZA8c0WirwQ8qGaIU+UFTjfN8y7w+C3v7epFXNKW4tAEmaY4GPsGG wYUQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e10-v6si7561401pln.161.2018.08.24.09.28.24; Fri, 24 Aug 2018 09:28:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbeHXUCG (ORCPT + 99 others); Fri, 24 Aug 2018 16:02:06 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33680 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726488AbeHXUCF (ORCPT ); Fri, 24 Aug 2018 16:02:05 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7OGOIkd015531 for ; Fri, 24 Aug 2018 12:26:43 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2m2jrwq2te-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 24 Aug 2018 12:26:43 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 24 Aug 2018 10:26:42 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 24 Aug 2018 10:26:37 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7OGQa5666781382 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 24 Aug 2018 09:26:36 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 665727805F; Fri, 24 Aug 2018 10:26:36 -0600 (MDT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B6CD78064; Fri, 24 Aug 2018 10:26:32 -0600 (MDT) Received: from morokweng.localdomain.com (unknown [9.80.232.133]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 24 Aug 2018 10:26:31 -0600 (MDT) From: Thiago Jung Bauermann To: linuxppc-dev@lists.ozlabs.org Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Alexey Kardashevskiy , Anshuman Khandual , Benjamin Herrenschmidt , Christoph Hellwig , Michael Ellerman , Mike Anderson , Paul Mackerras , Ram Pai , Anshuman Khandual , Thiago Jung Bauermann Subject: [RFC PATCH 09/11] powerpc/svm: Use shared memory for LPPACA structures Date: Fri, 24 Aug 2018 13:25:33 -0300 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180824162535.22798-1-bauerman@linux.ibm.com> References: <20180824162535.22798-1-bauerman@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18082416-0012-0000-0000-000016A594F9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009603; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01078233; UDB=6.00555984; IPR=6.00858207; MB=3.00022909; MTD=3.00000008; XFM=3.00000015; UTC=2018-08-24 16:26:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18082416-0013-0000-0000-0000542852A5 Message-Id: <20180824162535.22798-10-bauerman@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-24_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808240172 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anshuman Khandual LPPACA structures need to be shared with the host. Hence they need to be on shared memory. Instead of allocating individual chunks of memory for given structure from memblock, a contiguous chunk of memory is allocated and then converted into shared memory. Subsequent allocation requests will come from the contiguous chunk which will be always shared memory for all structures. While we were able to use a kmem_cache constructor for the Debug Trace Log, LPPACAs are allocated very early in the boot process (before SLUB is available) so we need to use a simpler scheme here. Signed-off-by: Anshuman Khandual Signed-off-by: Thiago Jung Bauermann --- arch/powerpc/kernel/paca.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index 1edf8695019d..3e2aca150ad2 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "setup.h" @@ -25,6 +26,33 @@ #endif #define LPPACA_SIZE 0x400 +#define SHARED_LPPACA_SIZE PAGE_ALIGN(LPPACA_SIZE * CONFIG_NR_CPUS) + +static phys_addr_t shared_lppaca_pa; +static unsigned long shared_lppaca_size; + +static void *__init alloc_shared_lppaca(unsigned long size, unsigned long align, + unsigned long limit, int cpu) +{ + unsigned long pa; + + if (!shared_lppaca_pa) { + memblock_set_bottom_up(true); + shared_lppaca_pa = memblock_alloc_base_nid(SHARED_LPPACA_SIZE, + PAGE_SIZE, limit, -1, MEMBLOCK_NONE); + if (!shared_lppaca_pa) + panic("cannot allocate shared data"); + memblock_set_bottom_up(false); + mem_convert_shared(PHYS_PFN(shared_lppaca_pa), + SHARED_LPPACA_SIZE / PAGE_SIZE); + } + + pa = shared_lppaca_pa + shared_lppaca_size; + shared_lppaca_size += size; + + BUG_ON(shared_lppaca_size >= SHARED_LPPACA_SIZE); + return __va(pa); +} static void *__init alloc_paca_data(unsigned long size, unsigned long align, unsigned long limit, int cpu) @@ -88,7 +116,11 @@ static struct lppaca * __init new_lppaca(int cpu, unsigned long limit) if (early_cpu_has_feature(CPU_FTR_HVMODE)) return NULL; - lp = alloc_paca_data(LPPACA_SIZE, 0x400, limit, cpu); + if (is_svm_platform()) + lp = alloc_shared_lppaca(LPPACA_SIZE, 0x400, limit, cpu); + else + lp = alloc_paca_data(LPPACA_SIZE, 0x400, limit, cpu); + init_lppaca(lp); return lp;