From patchwork Tue Mar 2 15:25:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 1446797 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:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) 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=desiato.20200630 header.b=mBbauPLn; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=iM3YsgrB; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=FdAN6P1q; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (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 4DrN4W3mMkz9sCD for ; Thu, 4 Mar 2021 05:36:27 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=DNG9PWupSTrhccQac3nSB3Yt/TmFI88rULm6wn6h9JA=; b=mBbauPLnf2v4ku1TU8jvIVy0cd xlqkczISevi0gh+g9LLmidPCbIpURWCSIKc6ftMPn3Twxp31W8evv+uWvGPmnV4vpJOCe1hArKFa1 8+6GoKinRoS+4oJz+iNfZAICCs7N7NjydwFWJByW6q3iqQVFWs0x66n5huubVtyWs38NRljkzVaFU Xot2NCtOCtedEJ2qk5bAlaS1k43iq7QFhti91+v30lf0RMJDdOYM4M/rMW6EgaQNuvQGYkPz4s/hm wG9Y02Nl+5/3BNWMTnOS1xg4+1e7iB8BQ7vGKTm8+iPFy1Q6YOI4Xks0jM1IjhjSUsBr1aN1OMH7E tE4ueklQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHWLz-0062fs-Rz; Wed, 03 Mar 2021 18:36:12 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHT0r-005H8s-V0 for opensbi@desiato.infradead.org; Wed, 03 Mar 2021 15:02:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=ciY70uULqfaUn8TNuExC71I1+IlYvSqtE1+MlzTP9UA=; b=iM3YsgrBOl3dU6BEk1ccS9j80F gJnebrym9kJGXCHA9Z4cPrIX2V2IKdp+TZ0UjRWaCqbdh253k00gXiHOlcod1isnswLAopALuLElu PchE++6LhhVpfDmGBVQHC0y6L7OYlyDyMd2pR8XRsVuUSmvEAF6CCQWpVBvhlJL66AVvjODmnKEZN t87QxMW9YihkX2RenWzWiwBkGAwY0Q5b/3RaliUmIE2LYZZqFjArNt3mIfYDDG7xxoYIaURcbFL/J H2sWztK3rC5jiR6TwiJg3zQvEWSF9s9B9J+Oy02zd5VzZwCGmGFgyNi9tbnRrGEsx36bx62FLS4kc ABvyjIvg==; Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6vO-00HLbH-QY for opensbi@lists.infradead.org; Tue, 02 Mar 2021 15:27:13 +0000 Received: by mail-pf1-x435.google.com with SMTP id r5so14018157pfh.13 for ; Tue, 02 Mar 2021 07:26:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=ciY70uULqfaUn8TNuExC71I1+IlYvSqtE1+MlzTP9UA=; b=FdAN6P1qeVeUa3CsnAntSAC9d13tsXn7gDxYkj3w67GTlskxExQeMfoV+Vwg82O4bv 4ZZyu/MYEWi9ltRxnHznGUyxi4/Rpw5Zj49GcLaA59ESlmyXIKPEmggy+up+1gzk03bJ Wg4Q/CMWXLJYReqY6AdCTq5LLRIYyeTT9liAF8xP0kvOG3tDD3IEVZgNjcJGiGl2Htvs V23ZJZRD8gUlL3gWxNtMLXfgMxjbmR+nd0vzlonbaHMY8imvzeo3pBGvyyIDgQU2SKjN t1vK5BNTLx4OCwIa0CrooAgpgcNSPCBLCH24+1c7PTVmN1pR0C4AQ0Re3CtpjkLh2DH0 ujag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ciY70uULqfaUn8TNuExC71I1+IlYvSqtE1+MlzTP9UA=; b=lQLkXq8Qsdc4grS+hR/aN/s2PDvpyXDsQOMKZf5d4QjnvIfpQiGwJCyV44zO11gtk0 WuNJtxCwPAvpmNvwANJ3odv6y+ULYU3A3BMoSZAPDiCKEUd3ZREgSTMrrZgMBqO84AkK tL3Gf8WCSfI7qcS/XKA05ZPOTeMOkhKL8BpW986+m01y0Oo/8zaoS4X0rLnmM5bWwbOY D9Gwa3/nhf8PuSQUNeGvM3S9qXZ/YiO/XE/bRbhX93rv2WHK/LN52KFCXyayjdx/NtwU OsYoCq89JfNXYfeoSAPxklfsW572jzJzBpVFVt4sn0MC623QW9raI8KgNSM4pmPU4c7C ssFw== X-Gm-Message-State: AOAM531jlqmsmfe7QVqVxCdP/Nyz7K2aTLHPp6stI2rKjVYviy7r1EXk dCHZfm2J4R5hvpW65HvtnrJQ9kKZaKMXtg== X-Google-Smtp-Source: ABdhPJzRI3ZnavUBj5QFi/PukNwxIzL0e6BjfPHKOKZlU16LBBKQx/YK00PF29OeP8FFoi50Zz3/tw== X-Received: by 2002:aa7:8c0f:0:b029:1ed:4d05:218c with SMTP id c15-20020aa78c0f0000b02901ed4d05218cmr3884909pfd.21.1614698757024; Tue, 02 Mar 2021 07:25:57 -0800 (PST) Received: from localhost.localdomain (61-230-7-198.dynamic-ip.hinet.net. [61.230.7.198]) by smtp.gmail.com with ESMTPSA id r123sm21630052pfc.211.2021.03.02.07.25.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Mar 2021 07:25:56 -0800 (PST) From: Vincent Chen To: opensbi@lists.infradead.org Cc: vincent.chen@sifive.com Subject: [PATCH 0/3] Support position independent execution Date: Tue, 2 Mar 2021 23:25:49 +0800 Message-Id: <1614698752-16085-1-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_152713_435301_AA7E51F7 X-CRM114-Status: GOOD ( 13.28 ) X-Spam-Note: SpamAssassin invocation failed X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch set enables OpenSBI to support position-independent execution so that one OpenSBI generic firmware can run on multiple platforms, even if they have different memory base addresses. However, the PIC code will decrease a bit of performance. The 2nd and 3rd patches are used to reduce this impact of the PIC. The performance loss of PIC comes from two additional operations. One is from the symbol relocation in the beginning stage, and another one is from the GOT reference (auipc + load GOT) in the OpenSBI lifetime. The former only affects the boot time, but the latter will affect the performance of the OpenSBI payload such as the Linux kernel. After analyzing the fw_payload.elf of the generic platform, 27 symbols use the GOT reference method to get their address. Fortunately, 17 of these symbols are accessed once during the initialized step. Only the remaining 10 symbols may be called repeatedly during the lifetime, which are 1. hartid_to_domain_table 2. hartid_to_scratch_table 3. sbi_hart_expected_trap 4. sbi_tlb_local_hfence_vvma 5. sbi_tlb_local_hfence_gvma 6. sbi_tlb_local_sfence_vma_asid 7. sbi_tlb_local_fence_i 8. sbi_tlb_local_hfence_gvma 9. sbi_tlb_local_hfence_vvma 10. sbi_tlb_local_sfence_vma From these 10 symbols, I think the IPI handler may be one of the critical and commonly used paths affected by the PIC mode. Therefore, I create two kernel modules, One keeps issuing the REMOTE_FENCE_I request and the other one keeps issuing REMOTE_SFENCE_VMA request. These two modules are executed on the unleashed board to measure the consumed time of the sbi_tlb_request(). I found the PIC causes a 1.6% and 4.1% performance loss in addressing REMOTE_FENCE_I and REMOTE_SFENCE_VMA, respectively. In addition, to observe the impact of PIC mode in the general usage cases, I use SPEC2006 to benchmark performance. However, I could not observe any performance impact from the results. Based on the above two results, I think the performance impact of the PIC may not be obvious in general usage. Just in case, this patch still creates an FW_PIC option for users to configure the build options. Vincent Chen (3): firmware: Support position independent execution firmware: fw_base: Use lla to access the global symbols defined in fw_base.S firware: Use lla to access all global symbols Makefile | 10 +++++ firmware/fw_base.S | 116 ++++++++++++++++++++++++++++++++++++------------ firmware/fw_base.ldS | 13 ++++++ firmware/fw_dynamic.S | 18 ++++---- firmware/fw_jump.S | 12 ++++- firmware/fw_payload.S | 8 +++- include/sbi/riscv_elf.h | 9 ++++ 7 files changed, 147 insertions(+), 39 deletions(-) create mode 100644 include/sbi/riscv_elf.h