Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1331990ioo; Fri, 27 May 2022 06:37:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw1NejUDKglbqcvENonjO/ExP2GKUSKNwqWN5RRl2XEzAt7LfEr+iG9SB/LbGVLMbxizhd X-Received: by 2002:a17:907:7ea7:b0:6fe:fce4:e802 with SMTP id qb39-20020a1709077ea700b006fefce4e802mr18846558ejc.47.1653658676976; Fri, 27 May 2022 06:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653658676; cv=none; d=google.com; s=arc-20160816; b=yLbeZcOBSf6v1FQpSNoo+pC5He1BaGlHZ2C/5k23NVfNA/GiA8fBe2Fcq4CheQdzPX E642EemVOaaYqnjSmnIp3FmDwaXbpp9ZCmQp5YPWK0SGBtsmY6bkwwxoUAShbWI99TCG Ete6y8HiDjiUu9cYXJWJHXrNoA4lomn83W2Hw12DIBxzi97S/WMItCKfynPTEcgBITOq sxYVNf4i6eMjf6fHz6fQcs2VSDU1TKvbzXsn0tEwUaQkrSwAVcD8i5I+7vKRQVnPuXcr bnD9mYyJajWpFcxOxO7aTp2W0w9nfBQB8AnfLJ50cojMHmdsTsVgih1HY9BhxJ4kiGCG yI7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2b8MlsVgy0PXNmTV8dy+TKz5ObSmm8PiUnaznemS1Kk=; b=eE8zdhWZXNUVqnR0Ivqq4gXu5O8UB8AoUh8TJijoTEDh0+elGXJp1heA3yCXrxhD0x 0DO+0qgTJ47pyGpmqXS13clbV3piI3XFbJTn59HU7L51tWANIc2lVmcbR5X+ipbwPWPX Cq/TANXOAfSxeJX91mhfaP3F5G76OhW9m+U6kvS5yfMGPh5TkUyQcXq9H0hhuXWFrJzy YwywtY8SwubtfdyL07qd4qh5wAcU+xuObHPESUWrYxLPSMbDGMaryP4ROvInrbgz/LUl exnHoA2ofKpNMEAp7BWr1G8ccDFH0SpJ6WCbo+SDYuuxRN8HglVz1TGG1sBmILWoTxdm noDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=RnE0k5m4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w10-20020a50c44a000000b0042abf683338si3743738edf.212.2022.05.27.06.37.30; Fri, 27 May 2022 06:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=RnE0k5m4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345336AbiEYXuA (ORCPT + 99 others); Wed, 25 May 2022 19:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345082AbiEYXt6 (ORCPT ); Wed, 25 May 2022 19:49:58 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D536BFDF for ; Wed, 25 May 2022 16:49:57 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id p190so353893ybg.4 for ; Wed, 25 May 2022 16:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2b8MlsVgy0PXNmTV8dy+TKz5ObSmm8PiUnaznemS1Kk=; b=RnE0k5m41tRreeyjV9rIBQp9IS8n51q9BWAAP9GOOssrHJTyMFtm4+pWqy0RYQfjxn yKed2IVryFnIF5xIWCU9MAdGEa/N9nXMxd6lVgHwZeq/y89d3yGfxFLVc3P7CG36Zp4Z KjivNcINMRfMiq3+Hz52iMRYUSqaAgCxB5S/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2b8MlsVgy0PXNmTV8dy+TKz5ObSmm8PiUnaznemS1Kk=; b=7bGKk0mexbC7Bs5o/02UE8SKdgiMmx0Vru3PQ6YbJ6ae+dsx6bFNqAGiOFx982+g3M yu2lRxzX7zVn7DCxehG+mB0GBEnhpFZyhgKV6I7QDu3JCZyv9GNly8iraC1FIljwLKIf GW1XlsTQxkR+RJdFxN4qqznd4ep8mJTJZAc7uMkaukdEtGIYnekQqZbT+vrNVKQ9n7IA KMVleuPIfXJXyVeNja2GJ1N/VzeZAehw12FxU6ABfqzCLAa6mfZQApAu+eOu1x6LZJB5 7wNKCYWzfvkswUeRn+56wWQKEl14gkxa0jH3hJOG+wWAX07HCJnLk/+t3XmeFtA6hIuS 8SNQ== X-Gm-Message-State: AOAM53046sbuEKW8Loc0xklmP/p6FJLI2tW/QOSmTpSL7PzrsrPMa+bg 4/aXHy3qHRwHq1OOYpSV6piA3ijF60UMQafMDA9w X-Received: by 2002:a25:a287:0:b0:656:29f4:b0c1 with SMTP id c7-20020a25a287000000b0065629f4b0c1mr3996630ybi.598.1653522597025; Wed, 25 May 2022 16:49:57 -0700 (PDT) MIME-Version: 1.0 References: <20220525151106.2176147-1-sunilvl@ventanamicro.com> <20220525151106.2176147-6-sunilvl@ventanamicro.com> <1e90b15b-8c73-0de8-2885-1292923b7575@canonical.com> <5829932A-6E45-46CA-AADA-14EDD903C4AD@jrtc27.com> In-Reply-To: <5829932A-6E45-46CA-AADA-14EDD903C4AD@jrtc27.com> From: Atish Patra Date: Wed, 25 May 2022 16:49:46 -0700 Message-ID: Subject: Re: [PATCH 5/5] riscv/efi_stub: Support for 64bit boot-hartid To: Jessica Clarke Cc: Heinrich Schuchardt , Ard Biesheuvel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Daniel Lezcano , Thomas Gleixner , Marc Zyngier , Atish Patra , Anup Patel , linux-riscv , Linux Kernel Mailing List , linux-efi , Sunil V L , Sunil V L Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 25, 2022 at 4:36 PM Jessica Clarke wrote: > > On 26 May 2022, at 00:11, Atish Patra wrote: > > > > On Wed, May 25, 2022 at 9:09 AM Heinrich Schuchardt > > wrote: > >> > >> On 5/25/22 17:48, Ard Biesheuvel wrote: > >>> On Wed, 25 May 2022 at 17:11, Sunil V L wrote: > >>>> > >>>> The boot-hartid can be a 64bit value on RV64 platforms. Currently, > >>>> the "boot-hartid" in DT is assumed to be 32bit only. This patch > >>>> detects the size of the "boot-hartid" and uses 32bit or 64bit > >>>> FDT reads appropriately. > >>>> > >>>> Signed-off-by: Sunil V L > >>>> --- > >>>> drivers/firmware/efi/libstub/riscv-stub.c | 12 +++++++++--- > >>>> 1 file changed, 9 insertions(+), 3 deletions(-) > >>>> > >>>> diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c > >>>> index 9e85e58d1f27..d748533f1329 100644 > >>>> --- a/drivers/firmware/efi/libstub/riscv-stub.c > >>>> +++ b/drivers/firmware/efi/libstub/riscv-stub.c > >>>> @@ -29,7 +29,7 @@ static int get_boot_hartid_from_fdt(void) > >>>> { > >>>> const void *fdt; > >>>> int chosen_node, len; > >>>> - const fdt32_t *prop; > >>>> + const void *prop; > >>>> > >>>> fdt = get_efi_config_table(DEVICE_TREE_GUID); > >>>> if (!fdt) > >>>> @@ -40,10 +40,16 @@ static int get_boot_hartid_from_fdt(void) > >>>> return -EINVAL; > >>>> > >>>> prop = fdt_getprop((void *)fdt, chosen_node, "boot-hartid", &len); > >>>> - if (!prop || len != sizeof(u32)) > >>>> + if (!prop) > >>>> + return -EINVAL; > >>>> + > >>>> + if (len == sizeof(u32)) > >>>> + hartid = (unsigned long) fdt32_to_cpu(*(fdt32_t *)prop); > >>>> + else if (len == sizeof(u64)) > >>>> + hartid = (unsigned long) fdt64_to_cpu(*(fdt64_t *)prop); > >>> > >>> Does RISC-V care about alignment? A 64-bit quantity is not guaranteed > >>> to appear 64-bit aligned in the DT, and the cast violates C alignment > >>> rules, so this should probably used get_unaligned_be64() or something > >>> like that. > >> > >> When running in S-mode the SBI handles unaligned access but this has a > >> performance penalty. > >> > >> We could use fdt64_to_cpu(__get_unaligned_t(fdt64_t, prop)) here. > >> > > > > It is better to avoid unaligned access in the kernel. There are some > > plans to disable > > misaligned load/store emulation in the firmware if user space requests > > it via prctl. > > Why? > To support prctl call with PR_SET_UNALIGN > Jess > > > We need another SBI extension to do that. The idea is to keep it > > enabled by default in the firmware but > > userspace should have an option to disable it via prctl. If we make > > sure that the kernel doesn't invoke any > > unaligned access, this feature can be implemented easily. > > > >> Best regards > >> > >> Heinrich > >> > >>> > >>> > >>>> + else > >>>> return -EINVAL; > >>>> > >>>> - hartid = fdt32_to_cpu(*prop); > >>>> return 0; > >>>> } > >>>> > >>>> -- > >>>> 2.25.1 > >>>> > >> > > > > > > -- > > Regards, > > Atish > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv > -- Regards, Atish