Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34232528rwd; Sun, 9 Jul 2023 07:42:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlFeCIwja05nUDrxCsn+XEvMTg4VoGZ8KhUgPnaqBYNANMzQWIv+5cwFLXkCUHtsXls6r/C6 X-Received: by 2002:a17:907:9045:b0:991:c9da:70da with SMTP id az5-20020a170907904500b00991c9da70damr9065261ejc.61.1688913736409; Sun, 09 Jul 2023 07:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688913736; cv=none; d=google.com; s=arc-20160816; b=NbHfUdYHRHLYavMFf6+ClqUPsdqBYTBxWrz6sRBFddMN21anCWH3e1OQb8OX1qHJJP 7eu77HEe1/GrX2qZWkyEUvOyVYbBo78sQ+DLaTnFUmETUQ6BB1iavWEZPHYBsuTtq+2v Qq90KFawptQ1I3VWr1bNB/fkIRXnGtit1zBS9GNJJdMRcfUuZCmZdHAreYZ9TWIl639x R4totmIOxecDHlV2dr7/f/Gtil/Zlt/UGl8zP3X8IRXV0+CyQd2YYrxk0xhWBHdaosAQ DkR6tF/8fbnNy6335tjykUUfng75H7h/5vN4eE67drvHDjRyZmr6wr87t62IXgKyoM6q s90A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qrfhJdqQ2y0Zvc0kTFKr7zE9aweR00SwiugzJUikyng=; fh=k+3MJHfr2F/fWihBiWe+KbkPGrGStRiGvIhJ/HRYQM4=; b=Fkcba5mrTUaNvOlTOoyh5zAiJwiCeWHNi1X/MgxLSiSP83/vJeqHwiSvvK2wvsFZDS rI8enaSQ1anHtVav6aLHHc3pZqBeqCruMhKrSvMXQgie1Ir89gE88lfEZ+DeJsWWAX1k Gzz/k16L6KKSYbNLQXt+zCbo2dHGogyeHYYr3QQm5l3DR4WhMiVHtj9ere/bGXa3lsyJ mhlu1knrAtoEcJQL235k8zw1cS39pDI1sgQZ6Uhfz0hK8e1S4qy1H/+wd+RKpR1UKxBL 434GrTmUrpEQ/mWw6yyFLatj1nKxPglZGniZafN91E3J4vOYqPLdr98w8ffLz3U3GnP4 Cjxw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a1709063c0700b0098e3c8beceasi6046783ejg.52.2023.07.09.07.41.50; Sun, 09 Jul 2023 07:42:16 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230395AbjGIOId (ORCPT + 99 others); Sun, 9 Jul 2023 10:08:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjGIOIc (ORCPT ); Sun, 9 Jul 2023 10:08:32 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC02297; Sun, 9 Jul 2023 07:08:29 -0700 (PDT) Received: from i53875a50.versanet.de ([83.135.90.80] helo=phil.localnet) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qIV5G-0002cH-Mi; Sun, 09 Jul 2023 16:08:18 +0200 From: Heiko Stuebner To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: Samuel Ortiz , linux@rivosinc.com, Conor Dooley , Andrew Jones , Anup Patel , linux-kernel@vger.kernel.org, "Hongren (Zenithal) Zheng" , Guo Ren , Atish Patra , =?ISO-8859-1?Q?Bj=F6rn_T=F6pel?= , Evan Green , devicetree@vger.kernel.org, Samuel Ortiz Subject: Re: [PATCH v3 4/4] RISC-V: Implement archrandom when Zkr is available Date: Sun, 09 Jul 2023 16:08:17 +0200 Message-ID: <1902759.taCxCBeP46@phil> In-Reply-To: <20230709115549.2666557-5-sameo@rivosinc.com> References: <20230709115549.2666557-1-sameo@rivosinc.com> <20230709115549.2666557-5-sameo@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_PASS,T_SCC_BODY_TEXT_LINE, T_SPF_HELO_TEMPERROR 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 Am Sonntag, 9. Juli 2023, 13:55:46 CEST schrieb Samuel Ortiz: > The Zkr extension is ratified and provides 16 bits of entropy seed when > reading the SEED CSR. > > We can implement arch_get_random_seed_longs() by doing multiple csrrw to > that CSR and filling an unsigned long with valid entropy bits. > > Acked-by: Conor Dooley > Signed-off-by: Samuel Ortiz > --- > +static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs) > +{ > + if (!max_longs) > + return 0; > + > + /* > + * If Zkr is supported and csr_seed_long succeeds, we return one long > + * worth of entropy. > + */ > + if (riscv_has_extension_likely(RISCV_ISA_EXT_ZKR) && csr_seed_long(v)) While this whole thing looks really nice, I don't think you can only check the ZKR existence though. To access the seed csr from supervisor-mode, it looks like the SSEED bit in the mseccfg register also needs to be set by firmware. And in the kernel we will likely need to check this setting somehow before enabling access. At least my qemu fails with an illegal instruction otherwise during the early random seed initialization. Heiko