Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5431999rdb; Wed, 13 Dec 2023 08:28:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGieMmnriTsmQrzRP8BUOqUKual8GvFsiBKSQ+HEhbldI0VHzWv9p6lu8KDGgoA4fvml73k X-Received: by 2002:a05:6358:52c9:b0:170:e4c6:3a74 with SMTP id z9-20020a05635852c900b00170e4c63a74mr4778383rwz.30.1702484890764; Wed, 13 Dec 2023 08:28:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702484890; cv=none; d=google.com; s=arc-20160816; b=W/vKpiqLM1QsTQyXlSle8ugkQzjPzCYhsSxUNscsxg7iqm6MqCMqA+KeJe/Vd1mQXv vdyTNnzNWRBXO1TcLyCNS0JDJgAMMXKZicm1/ZNxC/ZXf6TtaHQHfKn/mViiTOIPdKol 7OtO5Tz2eAAUY0OzaK/HrFA9nc1FEPcT/wEWZsGSZFNsNRN8VfnqQKyhzFi7EyL3wS2h NOuG0MFrXWSvIU5Y6rliT6C/oS7+7Fu+/mUIOn3D+ZfdDQV0yTOQ98z7mkeNJl3yHy+C RVxWRz6DabfMGHRwZxt7Cx5j/L5h7fHm2qql03+p9DEX4EsW4qWKMk9y+e3/KBS3z1Jp 84Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GwN+wNPTyEXCpp42soj4i392Xk+t7dyiyZpAtyDWMEo=; fh=UdO83i2RKaPBnDeQq1z0zv51M0BGl/MKBIjW00Ov7HU=; b=IcVQEIhJCm9CBs7QUOkWLQfLRmyHk2Y4AjfURa+/3efdKFdq7QWPSEMEmhPRrvb/ze 3mOA/TPKiLVaBob0CbcXrr1l7RFHbZ5ct5ZWT/wAy6j2jbO4kM0TxP3fexHX5K3VidkQ sRtIGquTINICkeDoSC58NRnmJzHy/ePSpeaoQOUEz5xbaihwd98i7YU4rClUV1gvtHgS ZvKfWoNwMDGXCujsXk/Ixma15M7dnBgmON+vEj6qadWGJtUnG4JwdOhGuGYi2GlXlFOQ Ayuv5a3u6V2mEcp5DcZsWTcJ/rgN2Hmv17F1loZ3hhaPpGHE8JTk/EzLx1UkYbMn0Kae /l5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nenhJP5d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s11-20020a65690b000000b005c6bc2367ebsi9548737pgq.216.2023.12.13.08.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 08:28:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nenhJP5d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 44B7280CF51B; Wed, 13 Dec 2023 08:28:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233516AbjLMQ1y (ORCPT + 99 others); Wed, 13 Dec 2023 11:27:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbjLMQ1x (ORCPT ); Wed, 13 Dec 2023 11:27:53 -0500 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BD93DC for ; Wed, 13 Dec 2023 08:27:59 -0800 (PST) Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-db538b07865so7368655276.2 for ; Wed, 13 Dec 2023 08:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702484878; x=1703089678; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GwN+wNPTyEXCpp42soj4i392Xk+t7dyiyZpAtyDWMEo=; b=nenhJP5dVQrEO2jkA5KSwztV01ushi3T66KvzjZen/j2fpGRCcUIktCEnUG6zzEUp6 ED6ybavjofqLt99cJXCw8tNCzbORqPV+EDhPi71OZyYp+ZVU7v+L00ZJcLmSHoaAmD0U GmdZEySL10eo2FirliaBSRyEj3deEA6Nr56Tt1lq+0Tx3i+IxOn2JD2CaCat+yUHxh3h t/t7gHppma6yQtrPyVNt0jqq6AoKduw5ZHgviSynLEuSbpUFZsyhqmfJwnRZHCYUsYWO rp2uEqo/+EwoKwdZLfOpjMr/DEMtV0GFuvVybrvsICDHAu4I5IQ7YHUp/FF96Dx7LTc7 CR9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702484878; x=1703089678; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GwN+wNPTyEXCpp42soj4i392Xk+t7dyiyZpAtyDWMEo=; b=i2m1wdQXUxLdFT9j8YTr/9OBCGxB3v/0WtLzxvzeR1XlWWSBF5BObrpHIw6feCHatw YdT7PS1oWNirtCD+RWHRjkxZoEtOVGgJIwWe36JsmJnlKiqs89qGh4nlrfR5zei8esyM bXqeEkZnL6GofnHfMVyxV5X60oP7HkGST8tXdh7tSLMMW5NNJiWdbkkpI6oSxpOUiZsu UmOC3gaBHi0ZecBBTsJjUr/mnYvPeiHnT1OCTmx1wEB0BUtci0FDXA37nmcasDBq0VK9 yWLcLix1FjneGNfUE/j8pYO11fBnuMqCdjCT2o7TuNuK5ugnB9bZaQnhNBNSYVQT3IGC 5hdQ== X-Gm-Message-State: AOJu0YxaCY78Vzudg81Cye5zt3bPtWAYvN36E+u/okKVjrCcyKxtYSwd dVmxODF3t5zbdx5K/Zxb+2HSy3t5zZapyqsvR6dKhg== X-Received: by 2002:a25:8051:0:b0:db5:4731:eeb8 with SMTP id a17-20020a258051000000b00db54731eeb8mr5500365ybn.18.1702484878223; Wed, 13 Dec 2023 08:27:58 -0800 (PST) MIME-Version: 1.0 References: <20231212235003.2036221-1-debug@rivosinc.com> <20231213-707b4e8b5a91ceedd557eb12@orel> In-Reply-To: <20231213-707b4e8b5a91ceedd557eb12@orel> From: Deepak Gupta Date: Wed, 13 Dec 2023 08:27:46 -0800 Message-ID: Subject: Re: [PATCH v1 2/2] riscv: envcfg save and restore on trap entry/exit To: Andrew Jones Cc: Palmer Dabbelt , Paul Walmsley , aou@eecs.berkeley.edu, apatel@ventanamicro.com, guoren@kernel.org, mchitale@ventanamicro.com, waylingii@gmail.com, greentime.hu@sifive.com, samitolvanen@google.com, Bjorn Topel , Conor Dooley , jeeheng.sia@starfivetech.com, Heiko Stuebner , Evan Green , jszhang@kernel.org, cleger@rivosinc.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 08:28:08 -0800 (PST) On Wed, Dec 13, 2023 at 4:24=E2=80=AFAM Andrew Jones wrote: > > On Tue, Dec 12, 2023 at 05:02:43PM -0800, Deepak Gupta wrote: > > On Tue, Dec 12, 2023 at 04:53:48PM -0800, Palmer Dabbelt wrote: > > > On Tue, 12 Dec 2023 15:49:25 PST (-0800), debug@rivosinc.com wrote: > > > > envcfg CSR defines enabling bits for cache management instructions = and soon > > > > will control enabling for control flow integrity and pointer maskin= g features. > > > > > > > > Control flow integrity and pointer masking features need to be enab= led on per > > > > thread basis. Additionally, I believe cache management instructions= need to be > > > > enabled on per thread basis. As an example a seccomped task on risc= v may be > > > > restricted to not use cache management instructions > > > > > > Do we have anything in the kernel that actually does that? Generally= we > > > need some use, I couldn't find any user-mode writable envcfg bits in = any > > > extesions I looked at (admittidly just CFI and pointer masking), and > > > unless I'm missing something there's no per-thread state in the kerne= l. > > > > > > > Cache management operations? > > As of now kernel blindly enables that for all the user mode. It will be= good if > > that is enabled on per-thread basis. Sure, all threads can have it enab= led by > > default. But if strict seccomp is enabled, I would argue that cache man= agement > > operations for that thread to be disabled as is done on other arches. A= s an > > example x86 disable rdtsc on strict seccomp. RISCV allows this CMO exte= nsion > > and I expect CMO to leverage this (currently it > > doesn't). > > > > I was being opportunistic here so that I can reduce number of patches o= n CFI > > enabling patchset. > > > > Will it be okay if I revise this patch to include with a usecase to res= trict CMO > > (say for case of strict seccomp on risc-v)? > > I opted to only expose cache block zero since giving userspace the > ability to invalidate cache blocks seems risky from a side-channel attack > perspective. I didn't pay attention. You're right, it's only cbo.zero that's exposed. I will roll up my patch with cfi set then. > > I'm no security expert, so feedback welcome, but I don't see a risk with > userspace being granted cbo.zero, even for strict seccomp processes. Yeah I don't see a risk with cbo.zero to strict seccomp thread either. > > Thanks, > drew