From patchwork Thu Oct 15 13:26:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1382679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=TdmVynqa; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=bma/671K; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=Ym8xyejG; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CBqq72lf8z9sRk for ; Fri, 16 Oct 2020 00:28:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pX731FFzUCtScya+EMM5Pcbswv6Tdvmn42a3X98EJaM=; b=TdmVynqafVtfQ4Q7hz7XbArti 1AHH58iVI/Ar7o9O6zDVFcvpQtb8HUTXZd/0Lqr5h7CdYm3qcOKTirjOIle4eE8jsvlP0qbr5F4aS Gm3NIOK1+8GMRaxZO+w4XpYC/1G87kgYULSOQm+E7iT54sFEI+ovX7+er5vp/jyZCAi23cAGh9ZbZ rjMPlg4v6iUATOWsZ+aOHEmzGdhPmS3wcEqyFs1PGkK8aPq7vwHJX+fBdmPQnkVFCQnpYyTFrhGSi Si+pRM/zSQwd/LmQsXfzJeTgNs/PH2e3ra0IM53apTo9pewEJpkcx6Th/ncGXbzNnwloBREW5ubPF y8T271M0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kT3Ii-0004Z8-8u; Thu, 15 Oct 2020 13:28:12 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kT3If-0004Vx-0G for opensbi@lists.infradead.org; Thu, 15 Oct 2020 13:28:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1602768488; x=1634304488; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=YfIExUeF5qxGAgO3aqk+5/vQZvlAtbsHQHFA40U3tQ4=; b=bma/671KopTTIlGfWY3r4cmxzX/PHch4xjnhMDUxXFq+2dJtWcqCmNME w2YsDW2jyBHe+EJjkvanwK3LpODzisVCfynycgNy4X6vIceFO9ofULUj3 VFda4XNkNeWHn+2RnpRE28wuYnGeRW85eqJa0AkE2ochVhokXaGOHAyEh Uz0jk3q5O/2Vu+KPZ04oRqZMdWhofGgK8n9YzISHtnp8INv1niW3jwV54 zRpzwR/giP3Oszvdc6nt9EVhe/rPGxGtvVHuGceDmNsI8RoGHGq5aTWIw f5+q0bil1PN7c7XHmXvmg6MFrZUtPugkTRLgOHehFZN2MlnAKucBvoEwq g==; IronPort-SDR: Gm9bUTrXBz8gxXyvd5RjkFgHADkckuvc6e7epinobO34TJ4/daKkHjvjBWJpJQqr/Z6TVuajQ+ dt/hDsbLESerg57Ja/2RYNRWw5OZ8PDIZx8LDRv7uTFMmXRH/DEER2AnGbeOCUor0ECJDILJdv khG6x5QKJ3BHTd5szHZ8dMsUxDi3/vlJbQkhYbbB8SdU0kN07997c89h+Cr0BnQDlS3hUNKjRV NnDOnznkgYhmX1Sda82dOhsM8v58hWUzMR45qyVlD9OXaQ/A7ekriosPZ2v7eNcCM/igkHSa9a wQ0= X-IronPort-AV: E=Sophos;i="5.77,379,1596470400"; d="scan'208";a="149952395" Received: from mail-bn8nam08lp2047.outbound.protection.outlook.com (HELO NAM04-BN8-obe.outbound.protection.outlook.com) ([104.47.74.47]) by ob1.hgst.iphmx.com with ESMTP; 15 Oct 2020 21:28:07 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PHP9vf/z6QKMXV9DF6qH+0awZ1zlUAYAJxg1BfeyeswT+QzyKeLIuo32Z5vgaedk6Wtx8KqVcfcHh3AlXo1vHFfuAtBMEi2W9b3t7dPzONIbPpZcBBNVyC0sVXxCSaNhFEnGZH5TyF22RpjDooyaBHG9yRlZEypN4+6u/c3ebR9nW1j9aGBn9iKz9mi678P3mZLp8CJ3OjgmmzDA2yFq6r4T4hOJxSlokbEn+EgSIxf7OWZABNIIG8hqhdUao/JTqQIgxv516eEs4O0XtxzzLVT71DNJKX1c3XWLE4ObGV5WuKNNLAHryj/l/1pUN7foFt7vV5AAUKG4x2pYXTpVzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZF1IVzoSEpRLrLp3YN2/62HayoNC5/SDWlHpz+MYYHU=; b=TO4s1WSPnE8kwsbhLWzt9SetW6llJZD8aoub+XIDfewDrUniCrDpAONrMp1JfOpKdk4WTXd2P5fvZ9pLnxR/jIToaCyFvkJMc7nhEUBWGF8iynCP15FxmQKYj5dQHEryfKYOGSuA+WfVD6tWdzP1alZDxpphv94XhdDFfzQhSSOV3MKwMNDDQsdhoNQ5bMXqBrKasr/8M+AaKMHgfkj7d3f+7ubohdl5FdZ0gOh3+BBySQRtYzZi2vNSydT90ZNcgh25rfN5Noh1okveVBFtZxzBhEq4mhgrgumI1XoZ/H/z7KXGE7Gv9scJDZoww6Y0aGUlnKqBSMWlFS1MVnltfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZF1IVzoSEpRLrLp3YN2/62HayoNC5/SDWlHpz+MYYHU=; b=Ym8xyejGkvg6F/x579OWAXu6CnWlv4vsw2ZeX3GZw/YAI/RyVZa6Fq8GFoFahIoEcG3Ld1WEo6NhA5sIRWGUUBp8aSBnqHUufEubpRr5CTOFD3aQ/E7njxGhzcLYY6fKY57YWIchJjvDNn4gVut5UO8dgHyieXNXoDWonJFpIIE= Authentication-Results: wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=none action=none header.from=wdc.com; Received: from DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) by DM6PR04MB6624.namprd04.prod.outlook.com (2603:10b6:5:1b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.21; Thu, 15 Oct 2020 13:28:07 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::d035:e2c6:c11:51dd]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::d035:e2c6:c11:51dd%6]) with mapi id 15.20.3477.021; Thu, 15 Oct 2020 13:28:07 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Subject: [PATCH v2 14/16] lib: sbi: Configure PMP based on domain memory regions Date: Thu, 15 Oct 2020 18:56:58 +0530 Message-Id: <20201015132700.2232820-15-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201015132700.2232820-1-anup.patel@wdc.com> References: <20201015132700.2232820-1-anup.patel@wdc.com> X-Originating-IP: [122.167.44.151] X-ClientProxiedBy: MAXPR0101CA0065.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::27) To DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.167.44.151) by MAXPR0101CA0065.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.22 via Frontend Transport; Thu, 15 Oct 2020 13:28:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3022d3b8-39c4-4780-3d34-08d8710e26ee X-MS-TrafficTypeDiagnostic: DM6PR04MB6624: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Jzhj7La4IlbOkVkxvx7qtT3P5H6Meagk79aJ0uYjO5g44wwUDnDZPn6gfHpkBNDQxg5iDdbUrxhMxjIF0/NM+O/iaK7c9IaXqWiPiUl6BoZtpTwNVBNRvzqGwBdtu2VY+EkCKO102WE3gmtFYIN76JMx0bNfNENANBONjJEhp9oqcLg2N+lScV+zzQIwq8szNNVcXEcnSQnS2G7IRmAB6IgKk4QCSCZfMiNe51ByrsSkz4b7dSU2rNxcDxAhN6PEVOgVymrEQvJAkRQMVI6t59b6ESkX6bDRzrUF/jIbPv/xZ5bqzEWPaQe5XbrkBVEbrOtuTkTvdJrsc3j5QLDZje6ur6mnmC61wJeeFm/wrPDBe35AkAJswk57xUI43fxc X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR04MB6201.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(376002)(39860400002)(136003)(366004)(346002)(2906002)(66946007)(110136005)(66556008)(5660300002)(44832011)(66476007)(36756003)(6666004)(316002)(54906003)(8886007)(8676002)(8936002)(86362001)(34490700002)(1076003)(52116002)(26005)(16526019)(186003)(55016002)(83380400001)(478600001)(956004)(2616005)(6636002)(4326008)(7696005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: a1X9NH19vybFxFaHMvPH0MFeXGCENHuRhM0zUR2t2W6I+6tFAW55Ckkph1PQl2sBrUCmqLOJLt7APZz6la0M2WYxLJMzJx2/bGa25kMjHxBvEsj/BIrSC1p+4QzEizdn1kGuXmZcoVlTJXxqNEeJa7MTVj+BWCmJ5yRECfA42ahh5i8lt+xQBQif0DQ8ETv1PsjNDS4HJAXNA2URbutX4GQVS1WCBt2RqLOvrlDvjxkk4kQjHduqdFa26dLbLrfU1JFD86CJ9muacfZhtk0Ih1dcBgaAD253r3RRHrGBXYpTF3B5MIjNHkWdl5zws4YmnuVIHLCnAvFpBwjSYahCi358vnmAUSWyS56l0M+XB0PDzmawo1VPFKjoz+laWhh2q/U7lUIrXp6IhWfG25uGZUJqiRkOT1B4YBHlvSmAE/rl3b6gvFz30jvIUz6Q+1odwnng479coxHGSgvlhvJ7j34MENCO3w2OXQiW9Zpzo5yHY51WRN1KMnt7qgJVLA60wbgLhoVm955fT439mOLV2lwPyiORKut8b/4i8TKKslQoZ9EyC6J4NYC+FF9Uvo2WccNcDxNY7bkLj94btiSeExMSLjB/egXK49hptGZiWwTGCldKt9adHb6LnAuyNE2N0FdAM2vOHvjoeNhX5xzxuw== X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3022d3b8-39c4-4780-3d34-08d8710e26ee X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2020 13:28:07.1332 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fvgmS+l5nNUjviZk9e12izq5fyjqTF1vu61eeeWbE2ySbj2xx+tgPo3v0TO2TtSNwLMDJ9GhrZ1y+dU2tWx53w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6624 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201015_092809_169488_C2CC9070 X-CRM114-Status: GOOD ( 17.18 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Anup Patel , opensbi@lists.infradead.org Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The PMP configuration on each HART should be only based on the memory regions of the assigned domain. This patch updates the sbi_hart_pmp_configure() function accordingly. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/sbi/sbi_hart.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index ea5d479..1871a1e 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -184,24 +185,30 @@ void sbi_hart_pmp_dump(struct sbi_scratch *scratch) int sbi_hart_pmp_configure(struct sbi_scratch *scratch) { - u32 pmp_idx = 0; - unsigned long fw_start, fw_size_log2; + struct sbi_domain_memregion *reg; + struct sbi_domain *dom = sbi_domain_thishart_ptr(); + unsigned int pmp_idx = 0, pmp_flags; + unsigned int pmp_count = sbi_hart_pmp_count(scratch); - if (!sbi_hart_pmp_count(scratch)) + if (!pmp_count) return 0; - /* Firmware PMP region to protect OpenSBI firmware */ - fw_size_log2 = log2roundup(scratch->fw_size); - fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL); - pmp_set(pmp_idx++, 0, fw_start, fw_size_log2); - - /* - * Default PMP region for allowing S-mode and U-mode access to - * memory not covered by: - * 1) Firmware PMP region - * 2) Platform specific PMP regions - */ - pmp_set(pmp_idx++, PMP_R | PMP_W | PMP_X, 0, __riscv_xlen); + sbi_domain_for_each_memregion(dom, reg) { + if (pmp_count <= pmp_idx) + break; + + pmp_flags = 0; + if (reg->flags & SBI_DOMAIN_MEMREGION_READABLE) + pmp_flags |= PMP_R; + if (reg->flags & SBI_DOMAIN_MEMREGION_WRITEABLE) + pmp_flags |= PMP_W; + if (reg->flags & SBI_DOMAIN_MEMREGION_EXECUTABLE) + pmp_flags |= PMP_X; + if (reg->flags & SBI_DOMAIN_MEMREGION_MMODE) + pmp_flags |= PMP_L; + + pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order); + } return 0; }