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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14A51C83F1B for ; Wed, 16 Jul 2025 07:33:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91D136B0093; Wed, 16 Jul 2025 03:33:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CDB46B0095; Wed, 16 Jul 2025 03:33:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BC966B0096; Wed, 16 Jul 2025 03:33:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6BBD76B0093 for ; Wed, 16 Jul 2025 03:33:47 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0FC1C1602CD for ; Wed, 16 Jul 2025 07:33:47 +0000 (UTC) X-FDA: 83669313294.29.538001A Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf28.hostedemail.com (Postfix) with ESMTP id 1B5ECC0006 for ; Wed, 16 Jul 2025 07:33:44 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=iEl+0O9T; dmarc=none; spf=pass (imf28.hostedemail.com: domain of debug@rivosinc.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752651225; a=rsa-sha256; cv=none; b=ghzuMokq4E/b1I4YlLZ3pkTH0XGzvpT8wtt3aPDN5dgmY2R19ol6C7kpPnC84KsWQzHVCb 4bXD1GWa8Iqd1H2neWRrmGHzF0fxyBz3kJIU9EWeGaJINVIjym2baMWn4ROHamsuqFIkgS WafIb/6IEdHRpVd9DLEzvLokWgRVfl8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=iEl+0O9T; dmarc=none; spf=pass (imf28.hostedemail.com: domain of debug@rivosinc.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752651225; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PW8oj8yyNVG5XPISXOtfA3n2P3zOnfj4By+Eha4u0hU=; b=imQqszG87LTAalG7gp5icji1ZMRLcBhN3TvlH5dtofk8Jc0ppwR+r6F2/LAT4zVy7QlHP3 a2EQgwfs6JH/Ir7Iwcun3Ud93CnNcKo/7OhJdbUGUE3ZQTJ42I/qtbFDp0Wr0YNgRhcqTF kC7FV/7hsTkGZasJvIYr1wSCbeQKQKM= Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e8bc13221eeso691528276.3 for ; Wed, 16 Jul 2025 00:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1752651224; x=1753256024; darn=kvack.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=PW8oj8yyNVG5XPISXOtfA3n2P3zOnfj4By+Eha4u0hU=; b=iEl+0O9TjFGdU1CoM3AfjYogZEa6n70n0ntRUc+PyJfN1JsSVt3+MiIHaMtcXM9lKh 84rFj22k2BFhubLLztdiGNWZx6W9TokRiIM6TAODuWOsV/6HlDnz3kgomSt6KbZyiEG3 hdqqrNUtL3mTC2MF95AXQXzrTon9el3yfRbv34eHRA5CnHXrHP0K/UPzAX4k5H3UcJZ9 Hmn6LZE1UofZElFVtUSjA67Zl6BJyHL9E6REKoyz3rTVi0sstkIQt0ZV7Io5sNh/Qc/P CULTkG8IFvzX1fLJ76WfVEgzSy7/IQsIwWNx0IGexnKLpdzvEmWYhhsVNQA4E0P8Z/bh 8E9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752651224; x=1753256024; 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=PW8oj8yyNVG5XPISXOtfA3n2P3zOnfj4By+Eha4u0hU=; b=MDbRaAlvzEcH/OQVDATeAiWRM1lo2QOYXXn/BVJ2FgI+eEoxmvhcj4QT6A3iEkWnzF e8h6faPCH9OdaXOlKU0zOJ++TGTkUz//L9x3geoIb4y6qv05VQF3J125Z/QKgLVAgZQ7 Fe5JUNA6ZJ3Czd/5fjOKaItd4sniddGXM35rraoNw/1q0V1ssErZsZ7s29xQf4AtF7TC NTR5WD94v+Y1ZV8PAEzbKbSbvODjS4AI+2OqAiFHSBP2Rgfpgkq6b73BJXZrlivdqx7u 77AdTMnsH66LsdTi8ryp5eoOxaEPV8/B0kBU3mLY9sdVuT5Sup+lcNIcfCbWSE6nIRxh J54Q== X-Forwarded-Encrypted: i=1; AJvYcCUo/YUYrvGYDedez4oxEFqTigjWrn3I/N1xJm/HsapMNJpNEeKv2wdCTNUO0ACZt3iR6wrbtudqZg==@kvack.org X-Gm-Message-State: AOJu0YzI1ULLAwjsMfe0cnlc3QX6cBpgK1aprlqapkqAHrmT9lUUHFgk YRt0b+a3d9LxXzBYuTDqRKgZnAF3RoyXBcIHgUneDfOF+sv/0et5tavnqNi7U9VwCRCQ9BpwACI oyoXFoVDiwGaOvra5YtHZuVkk4+hXpbcVq4zIQQ+06w== X-Gm-Gg: ASbGncuYSFNieKaIFE+xAxAvcF3xcGFfE3NUtWGgrRpHJp2y+MeT8hzjgQrtAZXxQ92 Jy41kKstog2gECy6iJqEuJUvvQkahPD/DHhY9oFQH/WwjPPr+fk4EUGlBH9AuSt+FpILiNTF1wc v0H12zGMxyySOh06lm0uwR099dBT2TniA7I6ur8sswuRaQNfqohMZsJWkODOpUSjQSUZrEhgRDR 20JOBI+ X-Google-Smtp-Source: AGHT+IEBFim0sebTg/GJVvyxJNrliMi5B8Z1CirXQugUtw/MAG7MtHjoXp3XBPYhkfJvHfUUj+zVmynVQDiKVlguiXc= X-Received: by 2002:a05:690c:6d0b:b0:6fb:b1dd:a00d with SMTP id 00721157ae682-7183516330bmr29836477b3.30.1752651223909; Wed, 16 Jul 2025 00:33:43 -0700 (PDT) MIME-Version: 1.0 References: <20250604-v5_user_cfi_series-v17-0-4565c2cf869f@rivosinc.com> <20250604-v5_user_cfi_series-v17-15-4565c2cf869f@rivosinc.com> In-Reply-To: From: Deepak Gupta Date: Wed, 16 Jul 2025 00:33:29 -0700 X-Gm-Features: Ac12FXyXP37ODEjfHSjK8_gGHbTe6nbCLu3r93joGlrq46qsQaqRghNBDnEKWgk Message-ID: Subject: Re: [PATCH v17 15/27] riscv/traps: Introduce software check exception and uprobe handling To: Zong Li Cc: 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 , =?UTF-8?Q?Bj=C3=B6rn_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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: ta4fknyyddfijo4wgo75ms1u8oxyz9aq X-Rspam-User: X-Rspamd-Queue-Id: 1B5ECC0006 X-Rspamd-Server: rspam02 X-HE-Tag: 1752651224-291165 X-HE-Meta: U2FsdGVkX18yfG+7aV2KpkG3Edb40Vd7NIy8moJfNLBRcouWahYOjHtfbTPtKY3IsSnwXCakCitM6iTM620X3LnmwfWvZHSjmJMCjREBzR0+U543lNydFWmWLmx83gmUO7tCgnwHNG0NBq+BAsvmCkowsAzGB7cJFKQUgKYraDITF435DcLJ6B7Bd10Z/3PsR3GUsBT0AY3jVpXmrN0M7potnuWTQaf0dIOT6FznGvQxniLDXRI2dNqEEF+3hWPkqFjwl/IhQU6cziE9EPUogRSV81IVoqYDLelSN54wa0mrpSPHetW4+xRLb9CwNFHuY0rBH8TiFvtTPMgTajpRv/OpjiBGv6eSOtGCCuYq93sIYukHRZ7KZ1kHmlW29Fz5GG3/z/zzx8zDT8pKZwnVKrooNuPdTVOBJ3g4tlLQorWeivQk8zVXH4azogj0OgJFSOPnyf1ysXhQ+z6onaGV+DlvRAstn9yAusAqTkL9eHy5s0OkWbKfgP8juNWroQfyqp/qcZEnM+3GpxZOO21m/yowDJ+seFXD2kP92zGMXD+zsgPh1ofbtPdl4jRXjfM/GR/Cdiauo9Ltuuz+ZIbmpJG6e9mVHRlmm8J7dk07OltHQRhL0fR1N/SXT91o0JRMCJLc5lzn51+BrXK+YQzTK5PhqFXhDRGIG0Mi6YJx6WReQ96xlTigcLIs7lry4gXd/evvQb6DvV2q5QZhRxbsJF73oQMsKlVVxry7Z4n4uSvu0JO8Z5F7Ayw1VCdPZULdXMB/HJk4FinAK9wSLyeBs/8jgTrVoRRqL7geqqon4KfOidXwFL0tl6RJI0KFithBbWONuaRftjZYMt+TebpvKOTIgagFx4Huqc5cfhzAFu3xLmbk/Dr3BXvO/0uN30gjrxYOKgWtupBxprrjpK0aNlDcv5ryQBvX43lxNjxIwzii91Sat4GXq8R9rO12PonDDga1O9pXGpnqXbH35Am Ung2JAjc 8n8bMyqDicJOBQCNcULbOh6Mbrn7D0Fp25gnGJMmT2Z8/aYQO+VUEQNdnoSMT5B+DHjZ3YeMhCbvu0VX+bNFuk0Jv/Nva/+2PBbhQhVAxcD53vbc0EIbMjgoaSdu5soFyNC6lNOwxrV9gR3KG2EDAG8j6fVkmIUeSvc3ddvROHgrykfgHAY5nqpvUJwSyvkyDTyoO7PN6Lp/yuLnQ9HUQRnX8A9f9hg9SFxaXW7NOtzhceClBlWvTnaV5IstC5aeYm4h8/tjrQnKcEQhsR4R+MZK6qkquoZGBpkn9+0MznI5BEVksjx80V2wiLY8faK+Y8bsMKBuZP1NFr8VrEyhCIaqd3VocrnLTUdelZ/iFigeLLkweNH52pLkyCg42HwGTWn0O6FwJDw2UxJm9gGGVgpnrPj7snIgKj8jGtDFfhQH0imXCpFuHhncAattiT+Wtp86wS/kvHmKZn4Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jul 15, 2025 at 7:06=E2=80=AFPM Zong Li wrote: > > On Wed, Jul 16, 2025 at 5:34=E2=80=AFAM Deepak Gupta = wrote: > > > > Hi Zong, > > > > > > On Thu, Jun 19, 2025 at 7:16=E2=80=AFPM Zong Li wr= ote: > > > > > > On Mon, Jun 16, 2025 at 3:31=E2=80=AFPM Zong Li = wrote: > > > > > > > > On Thu, Jun 5, 2025 at 1:17=E2=80=AFAM Deepak Gupta wrote: > > > > > > > > > > zicfiss / zicfilp introduces a new exception to priv isa `softwar= e check > > > > > exception` with cause code =3D 18. This patch implements software= check > > > > > exception. > > > > > > > ..... > > > > > > When a user mode CFI violation occurs, the ELP state should be 1, a= nd > > > > the system traps into supervisor mode. During this trap, sstatus.SP= ELP > > > > is set to 1, and the ELP state is reset to 0. If we don=E2=80=99t c= lear > > > > sstatus.SPELP, the ELP state will become 1 again after executing th= e > > > > sret instruction. As a result, the system might trigger another > > > > forward CFI violation upon executing the next instruction in the us= er > > > > program, unless it happens to be a lpad instruction. > > > > > > > > The previous patch was tested on QEMU, but QEMU does not set the > > > > sstatus.SPELP bit to 1 when a forward CFI violation occurs. Therefo= re, > > > > I suspect that QEMU might also require some fixes. > > > > > > Hi Deepak, > > > The issue with QEMU was that the sw-check exception bit in medeleg > > > couldn't be set. This has been fixed in the latest QEMU mainline. I > > > have re-tested the latest QEMU version, and it works. > > > > What was this issue, can you point me to the patch in mainline? > > Hi Deepak > The issue was that my QEMU setup somehow missed the change of > `target/riscv/csr.c` in your following patch: > https://github.com/qemu/qemu/commit/6031102401ae8a69a87b20fbec2aae666625d= 96a > After I upgraded to the latest QEMU source, I found the kernel issue > if we didn't clear sstatus.SPELP in the handler > Thanks Aah ok, got it. > > > > > > > > > > > > > > Thanks > > > > > > > > > + > > > > > + if (is_fcfi || is_bcfi) { > > > > > + do_trap_error(regs, SIGSEGV, SEGV_CPERR, regs->ep= c, > > > > > + "Oops - control flow violation"); > > > > > + return true; > > > > > + } > > > > > + > > > > > + return false; > > > > > +} > > > > > + > > > > > +/* > > > > > + * software check exception is defined with risc-v cfi spec. Sof= tware check > > > > > + * exception is raised when:- > > > > > + * a) An indirect branch doesn't land on 4 byte aligned PC or `l= pad` > > > > > + * instruction or `label` value programmed in `lpad` instr do= esn't > > > > > + * match with value setup in `x7`. reported code in `xtval` i= s 2. > > > > > + * b) `sspopchk` instruction finds a mismatch between top of sha= dow stack (ssp) > > > > > + * and x1/x5. reported code in `xtval` is 3. > > > > > + */ > > > > > +asmlinkage __visible __trap_section void do_trap_software_check(= struct pt_regs *regs) > > > > > +{ > > > > > + if (user_mode(regs)) { > > > > > + irqentry_enter_from_user_mode(regs); > > > > > + > > > > > + /* not a cfi violation, then merge into flow of u= nknown trap handler */ > > > > > + if (!handle_user_cfi_violation(regs)) > > > > > + do_trap_unknown(regs); > > > > > + > > > > > + irqentry_exit_to_user_mode(regs); > > > > > + } else { > > > > > + /* sw check exception coming from kernel is a bug= in kernel */ > > > > > + die(regs, "Kernel BUG"); > > > > > + } > > > > > +} > > > > > + > > > > > #ifdef CONFIG_MMU > > > > > asmlinkage __visible noinstr void do_page_fault(struct pt_regs *= regs) > > > > > { > > > > > > > > > > -- > > > > > 2.43.0 > > > > >