From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 3CC342882CE for ; Thu, 15 May 2025 08:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747298920; cv=none; b=od421m3rWdm+fWVI3yAsQYBLY8igAYoFRTBDKkC7ivV1JGcYMwpNKZsWtlqqqitool08oURhiVcDyW8BaNH5B0jZsljUZPMk8+i8qzUJcwPArIM5/n1rLCG8xl2ctwR54ArtUXJHatMykCkCd077l99zsYIWw0z/tcN5SgZWwUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747298920; c=relaxed/simple; bh=uafTKsLt5Y6vI+2YJVWbCoVLU1+w6d1TN41/6GcJe8w=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=PuqnDwql+kJs77QHgkm/I+tsLUSclujk9gGX+Q3Y5i4Xdt5c51TX0KISpjslwQb42VQVLOTLGXBiAZrnVhV58W2iuywhyfUCY05nJNsxwZXIaRtFfVahm/zkaB1aswUbsemRIG/OQ3iSFngDmzJD2j0cVW9ihZywo3dIj4vRIPo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=I+o+mqOr; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="I+o+mqOr" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-442ea0b3a9fso283615e9.3 for ; Thu, 15 May 2025 01:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1747298916; x=1747903716; darn=vger.kernel.org; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bdVLI+IKJQCwIaBP/4ipGt86DAIuj3sOKMK9lc4aqFc=; b=I+o+mqOrLwb6wAy3fZ6S3zjKPSqaM3CwDCRIeUdIay3/UdKVnn2nqClHp2i280eIJo tZyO0jy8xMq7nzDk/AqEDzGLQA6Av8h5IUIrV+E9571R5E2Zid8XpZXo6RayFQu3J9Et F/GBqCB1+3SvxUlFk0JZ8KNMo3Pt8iiTg8MJGPAZ2Y7gQJZL9F5OGqKptUTpV1kwK24L EOlzSCCEVIi2oevOVj9yLa8GrSIWcCDBU4NLrVldY0U3XkdWSWI2ytaUJ8Sq3ZQqb4cs u1f0G8OtL1VTWuMsykX7Bwk74nyGnyworNNU6w3awX+4DK4SlJeRIYuANTsjnT//Pq4q lnrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747298916; x=1747903716; h=in-reply-to:references:from:to:cc:subject:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=bdVLI+IKJQCwIaBP/4ipGt86DAIuj3sOKMK9lc4aqFc=; b=slxFLnFnT8w1GrXsA8vhO4rYD7MXda+J53eF/+/aVHG5Bhm3z/Yk24IDPrZPwjkaT8 3QQPQ/C4Bcbft6/1Rmf5dsItDoZId9TYykX/c39drqOST3UT8wPRywYMV22vSxQksxkX RPJY+dWi99/X7/sxJ3cqtij8fb8riNPU7EJvMYr9CjDd72tePfNzWu8hYIVf6KDDrDCj v2kJpT6t/2Ozt87GFh6+e7PT1vCNEv5frfnUu/NLkUQR1adkcidWYA/GoSdw9VymndSt +aV0NWqTaWXXkpzkUcufr5oDLPAHTb16Nmwk5AR3rq8+/reb3+CsEXZwxFSKwwcNicrE KXvQ== X-Forwarded-Encrypted: i=1; AJvYcCViwlKz6gqCikuh4qMHxKboh5pdcI/RSBtnGv7NYQov/hm/k+YKPSBqk2TGcGJI9uvQqsIYJRada3M=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1r2hKiCzAHVZbMKGaLtKmdRCYYlVahM4PxNgTeR2hqtousjO/ wTySH9bPuQyQd2IvtHn7qc4wUGik7ythv+7U93LZZ7DsjSANtG5woN2oI53a9Hg= X-Gm-Gg: ASbGncvurTu+GtpWXVaVfD7lcawGK40FPTa+V+jq5iSyq9G77NhsisLOHIaEPSFNV8f qr1AxhTsWTzJjKWrrZWlbpd2rSGZtb8Zyi3Z/Bf/rcefVrsPFcp/y1HLw6AQoGf2gSDMTFRUrpg dTX0fTj14L3mhYNuPkYfHCtIIWlBFWOzo9Z2QPBbbiqlDqTEDtIw5dlZGMscHgHjr09bMUT5paL Wi+R0gNyaub/z+JDdPwQ8AXSeg8PD1sXHn5KU7r8JUz6tETuxWjOjFS2pS9dztiyC73prz1G4hA KBTEAqn8So7fAC9z/tRoeZOzaokxt/iIh7HM+wreuuOPI8n+7QwjNL1g87U/ypopSHmaR36Ejax FPDGBcce2Epw= X-Google-Smtp-Source: AGHT+IFl5ofT8H2ymocVMBID7uffI6yQBoHWwntFgE3AOdsNMnKtMdzBwHwHlEbKzThnIcYnf09dKg== X-Received: by 2002:a5d:4311:0:b0:3a3:55b4:1abb with SMTP id ffacd0b85a97d-3a355b41b8emr294033f8f.12.1747298916300; Thu, 15 May 2025 01:48:36 -0700 (PDT) Received: from localhost (ip-89-103-73-235.bb.vodafone.cz. [89.103.73.235]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f5a2cf2bsm21822557f8f.80.2025.05.15.01.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 01:48:35 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 15 May 2025 10:48:35 +0200 Message-Id: Subject: Re: [PATCH v15 05/27] riscv: usercfi state for task and save/restore of CSR_SSP on trap entry/exit Cc: , , , , , , , , , , , , , , , , , , , , , , "Zong Li" , "linux-riscv" To: "Alexandre Ghiti" , "Deepak Gupta" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "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" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" From: =?utf-8?q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= 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> In-Reply-To: <122fc6cd-2e21-4fca-979d-bcf558107b81@ghiti.fr> 2025-05-15T09:28:25+02:00, Alexandre Ghiti : > On 06/05/2025 12:10, Radim Kr=C4=8Dm=C3=A1=C5=99 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=20 > code for a large number of extensions and only enable it at runtime=20 > depending on the platform capabilities. This way distros can ship a=20 > 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? (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.