From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A328E1BCA07 for ; Fri, 16 May 2025 15:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747409672; cv=none; b=AXc9FYlo1C47Oa2qU5WcOUasOvELoAE2w1e8HvbbGk+AVefk6VVAoGe52Tl6JEK+VLhpT5vTBt7dG2yHbs2VULhackbGmTSefY3A1/00KoSL+pfkQT6BuZCs2DzPTnjeN1tBxaxOxq1sHexkfZ4hk3HU6SQHqCteAvValAxPZxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747409672; c=relaxed/simple; bh=s7M35uwjD+aYg6o9dTgcW1bTJu8deexw+cwFb2Q66d8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YIR52hyzPXRxVs05gf/Ym36uB6ckcxIWcF0xsnhOKAmt5HA5B6OYkTvn/c5CV93n3x9aG0myzBeWW25NG1ZajxOmcuG9CC5qJulqRO2LUHFpvw2OjAIq95tDQyfjH/ZS6yPmu7AT3zkZvseKFxf83/w73nCnH45O79wocJSlZAs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=aNHk+Il8; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="aNHk+Il8" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-b0b2d0b2843so1813474a12.2 for ; Fri, 16 May 2025 08:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1747409669; x=1748014469; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=VTPOMqT5C2feU2knCk6fA/APYFa11AZmawpB2cqaoDc=; b=aNHk+Il8tY3wKlYMt8MKNZwFti/luK9M6uD2PQ9xQyLCJ7vcDjw+Wm7wBS2XdpfWpx KoKTdTtSvvxRzxBne9UFxCgPm/Iy49WKNu5yLRr0R3MJKgV75/6SmCD6a6E1AMcwpswu etbcgE59S7n6ZSjhDUCiZbdLQOYRPse4bgKHsAfDLRrmOzlLTSlgtzsS7/ckO2yiYzB5 g2adbQQxOrSxb9ZFDXSNYbYeKjMQGP3ta60NYFjtxLTRW3qg/fVMeFT7nfEv8JJn0hUQ coACE1nXsn/3uSg1AtNGtRpja+tGJeajxJ0IApyD2tUvF6kZ7h7BRTqBWIKs704bpsI7 HhzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747409669; x=1748014469; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VTPOMqT5C2feU2knCk6fA/APYFa11AZmawpB2cqaoDc=; b=kFt9A1+VJ9iOzQhe/YOMwFxisHfs4e0Xi8dNzyDv/C/BR36orO248JGBbh95A+7JNN gnaYA7IY/CQqZuRpor+M4LXvmgt57nFrARW9TIoFQ21O0dbmj+Ag6UTFPWtaRsP4WLa1 621goY1XxKd4Cq9Ljxwd4Z+zHUAgJkmLSQAMiS5mdtJQKJw5dG79NJyc1/6RmPUC4pL9 wHTSnjCxcvL966gh24eOf7GpdsoJMdZrLA9WEPE0o2ewmcAhh5UiI3ZM+z43Vk1cJkkw kwz19miEGpGfUirNImpLg/3aeOI3TBwOBZ2YcFD9GAfWtPJ7qFKNXgMZHQon+RujCpgv Wxrw== X-Forwarded-Encrypted: i=1; AJvYcCV+LXq+JAheZ+6J5acZPpZfPYJZoQmZ5bzUUTtnCjJbXZSa5k8q88fXX4URQA6x2bboUeiMzDwgsqo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6WRopMf6T0+SiC7IPYOXD9OpjTTj+tkH+SF05f5Nlox9EJjS1 O+Q5kxkISdY8kjshxLg4BOtm0Y3x5VQfrh3yPL1mkLgrirvY2xlmZ3wMG9ax/ho5oEs= X-Gm-Gg: ASbGncsNaObzV25DrlpTSQ1BJdTw+ENyyRFXhwQKAQmSqQlUmdVaGV//Qo15SMj4fFG u6Ehw7cCIC7TzFQnhINwtCXgmvVxC8oSD/WSY+wSdfHazPelphgsJfZ0zhwAWjhwBqFe/Bj//6T kOLqYRvS6f2Ht3a6bqTEWOGP42eTd+r73EneufQAmDHRCUv2IygKzlJbv6IfIhtO7V/erIl5m4+ LC8jupVYG2CyHfVX0UKLXLru8AWON1j7lA8Xfu16AvTax7GtWyYNZbERFk2bHnLNT4iAZYPKXMF WGbSmowKFLZybRMRjZZZ9Qxje9S66VsETAArQ5NhzPbcTpge9J4H1GOUZQrr3w== X-Google-Smtp-Source: AGHT+IFZckSqO5+1mOJ5q3W7tqhvvuTMvoIraIWCKDFfhzREKyJxJcIAzKyffAUquxEcLFZdJvL5nQ== X-Received: by 2002:a17:902:f60a:b0:22e:17ee:aa69 with SMTP id d9443c01a7336-231d45740d0mr41158275ad.50.1747409669319; Fri, 16 May 2025 08:34:29 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-231d4ac944esm15870145ad.49.2025.05.16.08.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 May 2025 08:34:28 -0700 (PDT) Date: Fri, 16 May 2025 08:34:25 -0700 From: Deepak Gupta To: Radim =?utf-8?B?S3LEjW3DocWZ?= Cc: Alexandre Ghiti , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan , Jann Horn , Conor Dooley , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, rust-for-linux@vger.kernel.org, Zong Li , linux-riscv Subject: Re: [PATCH v15 05/27] riscv: usercfi state for task and save/restore of CSR_SSP on trap entry/exit Message-ID: References: <20250502-v5_user_cfi_series-v15-0-914966471885@rivosinc.com> <20250502-v5_user_cfi_series-v15-5-914966471885@rivosinc.com> <122fc6cd-2e21-4fca-979d-bcf558107b81@ghiti.fr> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, May 15, 2025 at 10:48:35AM +0200, Radim Krčmář wrote: >2025-05-15T09:28:25+02:00, Alexandre Ghiti : >> On 06/05/2025 12:10, Radim Krčmář wrote: >>> 2025-05-02T16:30:36-07:00, Deepak Gupta : >>>> diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S >>>> @@ -91,6 +91,32 @@ >>>> +.macro restore_userssp tmp >>>> + ALTERNATIVE("nops(2)", >>>> + __stringify( \ >>>> + REG_L \tmp, TASK_TI_USER_SSP(tp); \ >>>> + csrw CSR_SSP, \tmp), >>>> + 0, >>>> + RISCV_ISA_EXT_ZICFISS, >>>> + CONFIG_RISCV_USER_CFI) >>>> +.endm >>> Do we need to emit the nops when CONFIG_RISCV_USER_CFI isn't selected? >>> >>> (Why not put #ifdef CONFIG_RISCV_USER_CFI around the ALTERNATIVES?) >> >> The alternatives are used to create a generic kernel that contains the >> code for a large number of extensions and only enable it at runtime >> depending on the platform capabilities. This way distros can ship a >> single kernel that works on all platforms. > >Yup, and if a kernel is compiled without CONFIG_RISCV_USER_CFI, the nops >will only enlarge the binary and potentially slow down execution. >In other words, why we don't do something like this > > (!CONFIG_RISCV_USER_CFI ? "" : > (RISCV_ISA_EXT_ZICFISS ? __stringify(...) : "nops(x)")) > >instead of the current > > (CONFIG_RISCV_USER_CFI && > RISCV_ISA_EXT_ZICFISS ? __stringify(...) : "nops(x)") > >It could be a new preprocessor macro in case we wanted to make it nice, >but it's probably not a common case, so an ifdef could work as well. > >Do we just generally not care about such minor optimizations? On its own just for this series, I am not sure if I would call it even a minor optimization. But sure, it may (or may not) have noticeable effect if someone were to go around and muck with ALTERNATIVES macro and emit `old_c` only if config were selected. That should be a patch set on its own with data providing benefits from it. > >(If we wanted to go an extra mile, we could also keep the nops when both > CONFIG_RISCV_USER_CFI and RISCV_ISA_EXT_ZICFISS are present, but > command line riscv_nousercfi disabled backward cfi.) > >Thanks.