From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BD57C433F4 for ; Fri, 24 Aug 2018 16:26:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4002021523 for ; Fri, 24 Aug 2018 16:26:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4002021523 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728323AbeHXUCG (ORCPT ); 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;