From patchwork Fri Sep 25 11:29:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1371196 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=n1BrSi0d; 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=gApEZ/y9; 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=KzWNox0I; 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 4ByV8Y270Kz9sSf for ; Fri, 25 Sep 2020 21:30:37 +1000 (AEST) 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=n1BrSi0drgPZZvA+/jS8dIZ9p rS4bLjNHz/ZjabEb0AnMAUNYMAtvHobfZNNh7h9xhbQCUQ7u6d2WCXMmKHwC8SkDLDBf45guJ1jua P8l36xP0tWxTZWHT3Rs3Zfs+Co+7p9EgDCJDV3vsbTJyMhnJH4A52CCBC8mjayBis/JSV2App1gHh EwRFawIcunfpbCTFQMYqfHq+rupwG3B7zgX+vB4eC1tMaGkn6CaPITpTesIEEPc4I0G6nDfTxQZ4x 1GSOE9T3tGhauVdSGHKslvoRAkYJMJbTMUGqdXTGnafyE3d1PiCfGvX1UNZ7A0XgZ7/AsnAB7brFb 9oQnYP1pA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLlvq-0004Xw-H1; Fri, 25 Sep 2020 11:30:30 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLlvh-0004PV-G0 for opensbi@lists.infradead.org; Fri, 25 Sep 2020 11:30:24 +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=1601033421; x=1632569421; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=YfIExUeF5qxGAgO3aqk+5/vQZvlAtbsHQHFA40U3tQ4=; b=gApEZ/y9I0IG7KfkNuO6fJFuRLouK6rFN50TKFj0ghd69BBpy3wPJOGO dNtP8GbWbF9+/WAb0MWSl+XsXEBUxydRTtukjwXY1dectcejUOwbR0oki ulhlE409Wbe9uOSb2NswwFD2dL2Kra7U9ScuQ6J4mkaGx2AY4eUTNwkQ/ aup01SuUPaDWKGqHkVsL7EshaKN+wThmFeUBFJCZZ6uzsebWYkmZyMTJa sjl6p3tQebBsER/dmJ+HSQ/uP5yickO9nhKnaDGfiG00K2I1Df+Z26CGm cRWQ3Rn7EfZV07KHEIFjzstQk0q+qzO/GGVtMYeIhnnnfHJIx/5BXcfin w==; IronPort-SDR: 4RfRNbeC+kOpo/tcH8jMpAPaJS9uUF5odhaOUhLE2iDNq2XxAEXDVrbrzuxXk9eSE6Em2eaA+j 26MTT+6OiBz84r20+oT2KOq06z2LlYlrNREUl0sGVSSUi6XncwqF+7wdMGSGXKgCeYZVTcMRV2 aq7PgBkezzftvZYr74qLgk0HmjBcwBnPQmeOCKzSUYQAwSZjgpGty4BLtN3Pz6Q/qozDGFHFYn TsxVETpSlZK91Xtu2DYgfUGq0vmlLe9+v/OHhsEIPEnv6kb3hFYOJPQgXA+vHIG3PA66FT+6kC ah8= X-IronPort-AV: E=Sophos;i="5.77,301,1596470400"; d="scan'208";a="152637955" Received: from mail-dm6nam12lp2169.outbound.protection.outlook.com (HELO NAM12-DM6-obe.outbound.protection.outlook.com) ([104.47.59.169]) by ob1.hgst.iphmx.com with ESMTP; 25 Sep 2020 19:30:19 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j2wjyZO6zsiHWdzbXqhAzuxX4xNlahjJJwIkUBHNlNvLuxg9hIjGNTBYLplQcoKmbhJ6JKvKbpnobUwQG+tBJ8fh8L4Ruv1+sBHYnuVjNNc4LtEPXcc52m/W3l0B4W4QLXzEp6oOyVSSvI0jOw71gcVdqSVSz01vN5634eS/6UzM2N4XbyLWEloHYGNqWVBolbBk2+q5nCns2DjQraY66h2nhPZ3f9N/0HX/551IrGKaFtTCaj/5akx+3gFOoc84nI9om9gCxtjBL5vKg2WOqeDkwKcn0hp9W9DQkdT1wXh/9xmVt4O2UGfp2NRmLh0RQoHOaoHihq7lUeA863tfDw== 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=hJyESqp17fbyG5e7y3Hs/Lg3JqNMSVo3ybmvlTQmOpOIaZyfg/Xi4q0bfOMSfzOtY2xP+fJNOgglZczP+fth14nt/wjG5odBFUPRH9dP0g6iz181ZpEadFS0WKZlKAW3y8lRSKflfK9JIzokQinWfqBbcnOxmFXQhmE1AiR8rkwqCOBlmj5lWqOgw9BCE6rTU20tAXwX62+rQXx+nATuh8EX9nAg8qzwla/7D+VQvssRa2pqVUzuuy0hS/c4QTFQEXVZdiH/+Ee8Dwluq66bfPQzSSa7EIkc0pZ/Z5EN/c8+Ehz3KJ7txLaEJLts3kbIHzinw4VFj7DJtoxhl7ynVg== 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=KzWNox0IUvaIphaj3aiGKWEjEMLYrlJvkt2uOApYp5zSucvven+EOj0Fxi8zT0WMxMgh+AE5KyCtJA5efp3NN1bJikUziJtTX6+X6Tn80+gLRVc+NnBK4Is0ZhpkRo7KKCd6S4lOBJlickkadoQrC7rFeEAG1aS8CN90Y0BOQZo= 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 DM6PR04MB6778.namprd04.prod.outlook.com (2603:10b6:5:24c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20; Fri, 25 Sep 2020 11:30:18 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::607a:44ed:1477:83e]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::607a:44ed:1477:83e%7]) with mapi id 15.20.3391.020; Fri, 25 Sep 2020 11:30:18 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Subject: [PATCH 14/16] lib: sbi: Configure PMP based on domain memory regions Date: Fri, 25 Sep 2020 16:59:12 +0530 Message-Id: <20200925112914.725846-15-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200925112914.725846-1-anup.patel@wdc.com> References: <20200925112914.725846-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0152.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::22) 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.179.69.106) by MA1PR01CA0152.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20 via Frontend Transport; Fri, 25 Sep 2020 11:30:16 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [122.179.69.106] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 789b3ed9-4f9c-4588-fd83-08d861466129 X-MS-TrafficTypeDiagnostic: DM6PR04MB6778: 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: G7596W+u8T90kDvga/+oAteZvPAU7uMdSveHRpsyQhHNdYkOcor++gE2rwkr6pKpiCq8WBu3rJE+fxKuwFY0bSGzixe29ACEnlnt3GpskKG/tSLbprP4V5pB8rYgXJKVv2MvuM/YMn6dGGZXIbggRfciFnrjLpMfYAggBJLpaQ0wxy5H0GfWkt5dfjNbZ1e2DnOgnEw71srhphkKeq/cuFX2l6wZp7d2db3R4+l53ACceLiCw2eK9T5ymXcq5fiI5Q4TSDh7dzQRdKDJqG3USxYKpDQtYLXTRbE9p8AiZjl73Mcd2SE9nl4JNZSh95gNB0K9UnP4x+ny0joTLi9OYIVRBx5bR5JOwcY9BAcUgjW1VlGWH54m0O0PEOp6V7xJ 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)(366004)(376002)(39860400002)(396003)(136003)(346002)(66556008)(66476007)(16526019)(8886007)(8676002)(2906002)(5660300002)(52116002)(7696005)(54906003)(36756003)(8936002)(86362001)(26005)(1076003)(316002)(6636002)(6666004)(55016002)(66946007)(478600001)(956004)(110136005)(44832011)(2616005)(83380400001)(4326008)(186003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: yQ+xTMHZffvjfjc/0LUICADkjx7CTF+1XMJJJ/E9OLSe0G8R2MW+wrQjOtGKeMoYD7njR+4Qy6Fz7989nLFi3ZgPPwVN041ihMBGLq9wp1TWt4WEkKUI9sqz2FHOxL0c/v1C74PAPo4qaYVFUf5nk5MNwW3PTbHKetuDDy1Xv7d3AH16gNndoY+2PdnToi2u4ALKAEg8Ht7IREAJ8Sh27SzAz20MVV6LCxyHY388ybDlMolzDdlSEUoIFqdgi3bcnQvwNwNUdddVd1xYWbW7KnHg9DcMPSrWNluWQM8c6WGW+XFcVchjAd77WM7HmB1tlz8nomPrDQYQFzjmFXEFS9fDj39ifUftOqUtRAAcbz+piXiUrnwGhkegbdBra5MIqaw91HkKdLo4zS04Cj84T9cctNvB8MmsklxkmcoMwL0CU078tpXeZYCM1HqA3jymMWQ1Jr/eSymIf9S84OvpY+RNaWvAB0c4KjY6A1hXNcDb2hXMK1sXQq5EB0L/FvLEgXKNE4nCDO3c7gE01crSTngj7AjpQlwMLPr3E3j9ufsFIJOyvLjilNgeCOxWCYTJgdf/zDMKrXRlydm6TiID4t4mUP7I/I+BJ/hxphKNKGNI96k545qAgVIxZgY93oJ4sNBLqCcCMJRRK2PpR3vA3w== X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 789b3ed9-4f9c-4588-fd83-08d861466129 X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2020 11:30:18.0930 (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: nvxN1HKj9eN4B6ZiYHjkbrX4kfqGmMTjhWw9shxNwFENano98T3IMw8+EFtgiStv516P2FXrZtHO1hFFruhaEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200925_073021_736597_0024137F X-CRM114-Status: GOOD ( 16.75 ) 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.153.141 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -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.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 --- 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; }