Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp294062ioo; Fri, 20 May 2022 22:44:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxOuaPyvJEYgDJHUMj331woI6ZxBRpUtqSQEmpFK8UAyw/gsGyF27YqMFHp0gqoMcPNRtD X-Received: by 2002:a05:6402:3507:b0:42b:dbe:2389 with SMTP id b7-20020a056402350700b0042b0dbe2389mr9261102edd.36.1653111875139; Fri, 20 May 2022 22:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653111875; cv=none; d=google.com; s=arc-20160816; b=KCoehZWWuHtObZ6rq6ANo10s6M5XShdcrBCZeb1CUxg2Oqb40FCG0s+zFg4gaScZw7 Ah63MqeD7GGNSekZY/HocKYkjAvdWqRZkakEM74NE5G/vmf4oskgQwCWb4AP1HC6YOIn GmPHYPONC+lvIV13+vL9qXNJFDSe44JslQR0YpG2kddhSWD1h2x85Gw2agu338pW/Bp8 6QXQ7lGoDK9IUGJAzojzqQeDQOL5c6vY+/hxChRafbaN4aZbv/4Vr9l2ZSChB0wHHhHn LUktrfKGSqdw0PjxJGrQlEe0HqJ9ynf15Y6cL1SJsp/oju5INYIQ7iQM3/ndLvR//zQX KcjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+tw51RCYcGj1foniXotGyrQteUlHw6mmELp0RHwCfbM=; b=vexQFQqzvIqMJgQKGlIZzCpZv7rXzJj/9l1uKLqRHHgyRH11Jl+5rkuuvLDP7USTrE 4RHIsu4Pu5m5GVxTEHdsfJZZSSJ7Lip2PhSF+cyAhhgOSkIZZTEiUxZQ+l1/tTZDPPqk SYdNhFVMEEJooe89xg029HBhgGiM5E6MpR6exLgiTS+q3zVqaow4+3MvldgyGnCO6qvW wq4y9tyegAZ2OphwX89YKQJjSwDOHv/QZiPRtLXi7bYdOFccDbSmZdg3g8/iwpG1/8st P4YJ+ofONGEqR8KcPaIc6dqWY+BcOnLFZPfji7zMxoFni8V94FKJQJk3ziacwZLE3rsx dGBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=QGegZ0Ay; 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 rl24-20020a170907217800b006f391c8ce03si8443770ejb.984.2022.05.20.22.44.00; Fri, 20 May 2022 22:44:35 -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=@ventanamicro.com header.s=google header.b=QGegZ0Ay; 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 S1345374AbiETEn4 (ORCPT + 99 others); Fri, 20 May 2022 00:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345402AbiETEnr (ORCPT ); Fri, 20 May 2022 00:43:47 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C52014AC97 for ; Thu, 19 May 2022 21:43:41 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id f10so7019919pjs.3 for ; Thu, 19 May 2022 21:43:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+tw51RCYcGj1foniXotGyrQteUlHw6mmELp0RHwCfbM=; b=QGegZ0Aye9ox2p2Qn/4S0srcNwplKH5EmehYsQWLax4ZKn/TePnw6ptFMtriZ5MGTt cRCrO2y0aujrYXFY6/zWO5ViduZDoc9QcN6HKspYEvsTai5SD7qyKUltZKxbY/qoGBkl DOB+ZVPpBmD2evL7YAMOj9wq+d0x5ytZGIFJseNer5UESLx0t4HzpeJLA37EBLMVWSob 4JSCQnrW/Km/0NpPOSrwWGMci8ytdcrPSeeOhU2GZQM018GtctGGc/TJ0vkZ/xKIqw81 cKrxe6dVofe4/SGdwTuxuLWBT8rRMcL22Ql5eZSSn1YllodXIhQDoGTaqfRTiBP4DiIh hMeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+tw51RCYcGj1foniXotGyrQteUlHw6mmELp0RHwCfbM=; b=8DGF07rLcmv0wuLnAvzbzjJX0zD1HpHtJwKQiB3GP779vQz8TiEUVqipFSRdsmYiqQ kgp8CrRTfUjSpSXPw4s84AjPbUhdyKSO+JttYMrVZ4CdYsj6tiApXgvwsYzaJBRWx2b+ jUFAb/f1VObc0KzPwMK6hxtKAYYdGdpQ6XGNNTN40K+kBg6cyCxp+8CHgr+627bCgd42 0QQvlJOewUFP7TzGCQ4WWhpO6nt/eC/w6SRelMvBqk5FEtAtB2+9602ZuFWC+TS5Zio/ MmpyfjOmYJlepRgdPsYgPCrVSQ7X1hmzHFvr/27FEcQ8siQzMgmK7GDEkqfB+5b1n9+h urgw== X-Gm-Message-State: AOAM531qThqan0aqG2HUcWQ6vcDrmalTUYi4iBPMPewqV5lVVo2eUecS csCXGF8vnnlloJtmLPmJFU1Vww== X-Received: by 2002:a17:902:d2c3:b0:161:ab47:8afe with SMTP id n3-20020a170902d2c300b00161ab478afemr7676365plc.8.1653021821057; Thu, 19 May 2022 21:43:41 -0700 (PDT) Received: from sunil-laptop ([49.206.9.238]) by smtp.gmail.com with ESMTPSA id r5-20020a63e505000000b003c63ae859d3sm4412015pgh.83.2022.05.19.21.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 21:43:40 -0700 (PDT) Date: Fri, 20 May 2022 10:13:32 +0530 From: Sunil V L To: Atish Patra Cc: Ard Biesheuvel , Heinrich Schuchardt , Palmer Dabbelt , Paul Walmsley , Albert Ou , Ilias Apalodimas , Atish Patra , Anup Patel , Jessica Clarke , Abner Chang , linux-efi , Linux Kernel Mailing List , linux-riscv , Palmer Dabbelt Subject: Re: [PATCH V4 1/1] riscv/efi_stub: Add support for RISCV_EFI_BOOT_PROTOCOL Message-ID: <20220520044332.GA4509@sunil-laptop> References: <20220518095646.47548-1-sunilvl@ventanamicro.com> <20220518095646.47548-2-sunilvl@ventanamicro.com> <04ed20b1-e312-dfc2-c314-02750c076681@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, May 19, 2022 at 11:07:28AM -0700, Atish Patra wrote: > On Thu, May 19, 2022 at 1:14 AM Ard Biesheuvel wrote: > > > > On Thu, 19 May 2022 at 08:17, Heinrich Schuchardt > > wrote: > > > > > > > > > > > > On 5/18/22 23:03, Ard Biesheuvel wrote: > > > > On Wed, 18 May 2022 at 11:57, Sunil V L wrote: > > > >> > > > >> This patch adds the support for getting the boot hart ID in > > > >> Linux EFI stub using RISCV_EFI_BOOT_PROTOCOL. This protocol > > > >> is preferred method over existing DT based solution since it > > > >> works irrespective of DT or ACPI. > > > >> > > > >> The specification of the protocol is hosted at: > > > >> https://github.com/riscv-non-isa/riscv-uefi > > > >> > > > >> Signed-off-by: Sunil V L > > > >> Acked-by: Palmer Dabbelt > > > >> Reviewed-by: Heinrich Schuchardt > > > >> --- > > > >> drivers/firmware/efi/libstub/efistub.h | 7 ++++++ > > > >> drivers/firmware/efi/libstub/riscv-stub.c | 29 +++++++++++++++++++---- > > > >> include/linux/efi.h | 1 + > > > >> 3 files changed, 32 insertions(+), 5 deletions(-) > > > >> > > > >> diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h > > > >> index edb77b0621ea..aced62a0907e 100644 > > > >> --- a/drivers/firmware/efi/libstub/efistub.h > > > >> +++ b/drivers/firmware/efi/libstub/efistub.h > > > >> @@ -720,6 +720,13 @@ union efi_tcg2_protocol { > > > >> } mixed_mode; > > > >> }; > > > >> > > > >> +struct riscv_efi_boot_protocol { > > > >> + u64 revision; > > > >> + > > > >> + efi_status_t (__efiapi * get_boot_hartid)(struct riscv_efi_boot_protocol *this, > > > >> + size_t *boot_hartid); > > > > > > > > size_t is not a EFI type, and your spec uses UINTN here, which is > > > > equivalent to 'unsigned long'. However, jump_kernel_func() takes a > > > > unsigned int for the hartid. Please clean this up. > > > > > > unsigned long and size_t have the same number of bits. This seems to be > > > a question of taste where we should follow the maintainer. > > > > > > > We use unsigned long wherever the UEFI spec uses UINTN. This is not a > > matter of taste, really. > > > > > jump_kernel_func() assuming boot hart ID to be an unsigned int is not in > > > line with the RISC-V ISA which allows to use all xlen bits. > > > > > > > > > > > > > > >> +}; > > > >> + > > > >> typedef union efi_load_file_protocol efi_load_file_protocol_t; > > > >> typedef union efi_load_file_protocol efi_load_file2_protocol_t; > > > >> > > > >> diff --git a/drivers/firmware/efi/libstub/riscv-stub.c b/drivers/firmware/efi/libstub/riscv-stub.c > > > >> index 9c460843442f..012504f6f9a4 100644 > > > >> --- a/drivers/firmware/efi/libstub/riscv-stub.c > > > >> +++ b/drivers/firmware/efi/libstub/riscv-stub.c > > > >> @@ -23,7 +23,7 @@ > > > >> > > > >> typedef void __noreturn (*jump_kernel_func)(unsigned int, unsigned long); > > > >> > > > >> -static u32 hartid; > > > >> +static size_t hartid; > > > >> > > > > > > > > and here > > > > > > > >> static int get_boot_hartid_from_fdt(void) > > > >> { > > > >> @@ -47,14 +47,33 @@ static int get_boot_hartid_from_fdt(void) > > > >> return 0; > > > >> } > > > >> > > > >> +static efi_status_t get_boot_hartid_from_efi(void) > > > >> +{ > > > >> + efi_guid_t boot_protocol_guid = RISCV_EFI_BOOT_PROTOCOL_GUID; > > > >> + efi_status_t status; > > > >> + struct riscv_efi_boot_protocol *boot_protocol; > > > >> + > > > >> + status = efi_bs_call(locate_protocol, &boot_protocol_guid, NULL, > > > >> + (void **)&boot_protocol); > > > >> + if (status == EFI_SUCCESS) { > > > >> + status = efi_call_proto(boot_protocol, > > > >> + get_boot_hartid, &hartid); > > > > > > A lot of the kernel code seems to be unfit to handle hart IDs exceeding > > > INT_MAX (e.g. sbi_cpu_is_stopped()). Until this is fixed we have to > > > treat hartid > INT_MAX as an error. > > > > > > > This is an issue in the core kernel code, not in the EFI stub. As you > > pointed out, the ISA implies UINTN / unsigned long here, and if the > > startup code cannot deal with that, it can be fixed separately. > > It was kept as unsigned int because hartid > INT_MAX is very unlikely to happen. > But I agree that we should just follow the spec(allowing XLEN bits for > hartid) and > change "unsigned int" to "unsigned long" wherever hartid is concerned. > > As the hartid is changed to unsigned long, get_boot_hartid_from_fdt > should be fixed as well. > Currently, it is using fdt32_to_cpu. I am working on a separate patch series to modify these instances. Will send soon for your feedback. Thanks Sunil > > > > -- > Regards, > Atish