From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A991DC27C7C for ; Fri, 20 Jan 2023 14:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbjATOaT (ORCPT ); Fri, 20 Jan 2023 09:30:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbjATOaS (ORCPT ); Fri, 20 Jan 2023 09:30:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772A979297; Fri, 20 Jan 2023 06:29:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A8C81B82853; Fri, 20 Jan 2023 14:29:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 237E9C4339B; Fri, 20 Jan 2023 14:29:33 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="NTHbstKf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1674224971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=F9kOqvxWdJiZ6o7rLV7rek2JVGrJsZXSaK0nvleVzCA=; b=NTHbstKfPp3u89snVVs+oFRiOmLj7/9+v4hS84e1+clIoPhsJ2kSbFe1y7Ve3fpUvfhDFY RBcamZ38ta96TPzy+pU4lTKfZ8wbvpW/izzz3c6W+tHXCN5ZL8y0SX+AqrocY7EgB2oo7F 1Nc0qLsaQSetYUtiIFFpE6YtUNUcr48= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c179fd18 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 20 Jan 2023 14:29:31 +0000 (UTC) Date: Fri, 20 Jan 2023 15:29:14 +0100 From: "Jason A. Donenfeld" To: Yann Sionneau Cc: Arnd Bergmann , Jonathan Corbet , Thomas Gleixner , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Will Deacon , Peter Zijlstra , Boqun Feng , Mark Rutland , Eric Biederman , Kees Cook , Oleg Nesterov , Ingo Molnar , Waiman Long , "Aneesh Kumar K.V" , Andrew Morton , Nick Piggin , Paul Moore , Eric Paris , Christian Brauner , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jules Maselbas , Guillaume Thouvenin , Clement Leger , Vincent Chardon , Marc =?utf-8?B?UG91bGhpw6hz?= , Julian Vetter , Samuel Jones , Ashley Lesdalons , Thomas Costis , Marius Gligor , Jonathan Borne , Julien Villette , Luc Michel , Louis Morhet , Julien Hascoet , Jean-Christophe Pince , Guillaume Missonnier , Alex Michon , Huacai Chen , WANG Xuerui , Shaokun Zhang , John Garry , Guangbin Huang , Bharat Bhushan , Bibo Mao , Atish Patra , Qi Liu , Jiaxun Yang , Catalin Marinas , Mark Brown , Janosch Frank , Alexey Dobriyan , Benjamin Mugnier , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-audit@redhat.com, linux-riscv@lists.infradead.org, bpf@vger.kernel.org Subject: Re: [RFC PATCH v2 12/31] kvx: Add other common headers Message-ID: References: <20230120141002.2442-1-ysionneau@kalray.eu> <20230120141002.2442-13-ysionneau@kalray.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230120141002.2442-13-ysionneau@kalray.eu> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Hi Yann, On Fri, Jan 20, 2023 at 03:09:43PM +0100, Yann Sionneau wrote: > +#include > +#include > + > +extern unsigned long __stack_chk_guard; > + > +/* > + * Initialize the stackprotector canary value. > + * > + * NOTE: this must only be called from functions that never return, > + * and it must always be inlined. > + */ > +static __always_inline void boot_init_stack_canary(void) > +{ > + unsigned long canary; > + > + /* Try to get a semi random initial value. */ > + get_random_bytes(&canary, sizeof(canary)); > + canary ^= LINUX_VERSION_CODE; > + canary &= CANARY_MASK; > + > + current->stack_canary = canary; > + __stack_chk_guard = current->stack_canary; > +} You should rewrite this as: current->stack_canary = get_random_canary(); __stack_chk_guard = current->stack_canary; which is what the other archs all now do. (They didn't used to, and this looks like it's simply based on older code.) > +#define get_cycles get_cycles > + > +#include > +#include > + > +static inline cycles_t get_cycles(void) > +{ > + return kvx_sfr_get(PM0); > +} Glad to see this CPU has a cycle counter. Out of curiosity, what is its resolution? Also, related, does this CPU happen to have a "RDRAND"-like instruction? (I don't know anything about kvx or even what it is.) Jason