From nobody Sat Oct 4 00:32:12 2025 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 C57D92980C2 for ; Fri, 22 Aug 2025 17:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755884848; cv=none; b=XDP0yZHQzfbK6AVpQ8Mzp7zBqRaUZUalT4HsybPzY3DMdD5627BUmec58abqufE7lQyh349GJpPAxRMeTWP5u2jjgEJOXoiiWuTByRwfPg7Vxa7XQCx0cWv2IyuiQyXnZ8AUOAdC6RlupqQUDwMjTtmvB989cNrhOPIGOfnJmvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755884848; c=relaxed/simple; bh=0b+k1Da34Ie81q2wS6yZp0j3E9D5ClJNu8JRMBnHi+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+9wqLb7y6iKouw7+uaoinNAgCliaxrC3KPy+bu1Fkfpa2DJoL9jTuHimtIPZV5bwe9M63WiHiccG94ZX9ot9i+lAvyOxKYm+Dt9qIlG5ZthA2pmd2Gju1mo2IPe8C/BtqW9Z4QUH5e+6rtFTaoAbo+M8Lcyd1uqzjqgjq0lz24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b=OfCFDmNN; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (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 header.i=@rivosinc.com header.b="OfCFDmNN" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4b297962b24so23401921cf.2 for ; Fri, 22 Aug 2025 10:47:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1755884845; x=1756489645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7icmFEtMbjG8nHUlUz3H6xEpzLvZfrYx0hP4AUrTZT0=; b=OfCFDmNNY64q0WQPlHvyCU01UrN1O7uFPdUYZGLx0gq160X8cjbGA6BXYsice8kGT9 wuEOwiNl1w4Q+dE9CWSycC0eoFwKKguwPhKYsaJC2RKC8cm8sZqUGYtzUfuUYOvHVHxJ /Dd3snX4ScJbxhSb04vqSOj3UqLNR3fv0qLyynTX5fHvRf3qNAImmbMam6aQDtS0RrOc JI1bMoTYU8PPxCOIs+6Mwkmmvmq0Ezdc83d/grP5F59lZXe1lKB3Fv0vaA41zvrdUx30 HboVj4nKplV2V9fWIMWA5HuGJ9pF+zZQJMFzijMWMKehgpxhX870AQ5eC7sgg6FSmq7P 40eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755884846; x=1756489646; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7icmFEtMbjG8nHUlUz3H6xEpzLvZfrYx0hP4AUrTZT0=; b=Z/BkxVaAWn7bevVovD/N84xyUnOHvmevCf73PzWG2MFGZ9pGRmJAhZCsidvwqrcr+1 Rq5H17m/HRu6MGyUrY1Ba5pgwmK0nOHuuUdh0Ig+5reo5ji7Tj5kU44BX0g1X0ixtNmT PxZqjUBTZjgN47T+5jmaX4oJPst2Z+qjmb+pl551QamJQ5ekt0H0piHucCAo/bvB+VEH xZZe5Aj8uZmWNHJNFr6cnoXJPtd6H3Np9b/JahAAYdAxKWUpSATkMj1IP+xBowFUof9t B0WFNVt+NgDYFc//sGsEO+42bwLWMp2mAIiXjZK2i/5ONAdel34oQs1IUxTsVA7H10NC 8XYg== X-Forwarded-Encrypted: i=1; AJvYcCVE5Bfy+NL1mtlMZ8S/T0Jg663myNDum1XvZfYbgzmoRJy6vihzjFmpf/IuuPeI1a3IhDhYEO22LRurfks=@vger.kernel.org X-Gm-Message-State: AOJu0Yww33pLkil0bPllxYupZzBIwKPbPUv3jo7v7RiFz8mR2+cFVrO5 gS/r5E5iDnPWNeC0gjhu1u6/dcjoCsIqBuXG3lLMnki4amB5EsLTx3RpPvWSm1Gt3Hg= X-Gm-Gg: ASbGncsqyXcbzptQJEOGWGdLZZILO0VHnVtSWWvpdzPVPErZGQX8zV53DFu6fYfp92s 3GFk7hW21fmY5x8BLK9XTnoDK/GMwFe+m4FVhgFG+zg6HaRUVLOS3zT4GKNj1NwAvUtTnZqDUan DXY7Z86ilQTP06Z/Cko8xPgMN3WprDUlgo7C8fEwXbt3zs0LPHaLDjO0VM2ct6XEHrg6pNHzNSZ n1S0lTQYPEFVbrtWMa5LykzMBxDNJ8X2Gk+QgZhRGVcxrafNGGrqjm5ke+heervYXW3mQlpe+Qr zNNwcElOvbfNVAAZ9PH7D3K20v/AzLviYT+jR7VyF/K32+Zdw9rmc2zEExgPPwPHKw2PZyJICoN gfFgRZbssd0MNx7Hdo/kDRSVY30C2VhyHM4or9xaJc5Xq+gg2ZqFNMvA7EbZAU6PSgVbb3TVZRf 6/+lXLiQ== X-Google-Smtp-Source: AGHT+IGt5FtRUkeNaYf2QqcOOYK1voNcUZefaLnp0B87objwjhy4KKvTzMxzHCr1EhOf/GN0KqwnNQ== X-Received: by 2002:ac8:5dd1:0:b0:4b1:103b:bb6f with SMTP id d75a77b69052e-4b2aab276d4mr43535751cf.61.1755884845347; Fri, 22 Aug 2025 10:47:25 -0700 (PDT) Received: from jesse-lt.jtp-bos.lab (pool-108-26-215-125.bstnma.fios.verizon.net. [108.26.215.125]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4b2b8e6023asm3121361cf.53.2025.08.22.10.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Aug 2025 10:47:25 -0700 (PDT) From: Jesse Taube To: linux-riscv@lists.infradead.org Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Oleg Nesterov , Kees Cook , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang Kan" , Shuah Khan , Jesse Taube , Himanshu Chauhan , Charlie Jenkins , Samuel Holland , Conor Dooley , Deepak Gupta , Andrew Jones , Atish Patra , Anup Patel , Mayuresh Chitale , Evan Green , WangYuli , Huacai Chen , Arnd Bergmann , Andrew Morton , Luis Chamberlain , "Mike Rapoport (Microsoft)" , Nam Cao , Yunhui Cui , Joel Granados , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Sebastian Andrzej Siewior , Celeste Liu , Chunyan Zhang , Nylon Chen , Thomas Gleixner , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Vincenzo Frascino , Joey Gouly , Ravi Bangoria , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Joel Stanley Subject: [PATCH 3/8] riscv: insn: Add get_insn_nofault Date: Fri, 22 Aug 2025 10:47:10 -0700 Message-ID: <20250822174715.1269138-4-jesse@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250822174715.1269138-1-jesse@rivosinc.com> References: <20250822174715.1269138-1-jesse@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@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" get_insn_nofault uses get_insn with pagefaults dissabled, allowing it to be called in an atomic context. Signed-off-by: Jesse Taube --- Unsure if copy_from_kernel_nofault is an acceptable replacement for direct dereference in __read_insn. RFC -> V1: - Add new function instead of using copy_from_user_nofault V1 -> V2: - No change --- arch/riscv/include/asm/insn.h | 1 + arch/riscv/kernel/insn.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/arch/riscv/include/asm/insn.h b/arch/riscv/include/asm/insn.h index ba74e5b8262c..f87e0a48f786 100644 --- a/arch/riscv/include/asm/insn.h +++ b/arch/riscv/include/asm/insn.h @@ -553,6 +553,7 @@ static inline void riscv_insn_insert_utype_itype_imm(u3= 2 *utype_insn, u32 *itype #include =20 int get_insn(struct pt_regs *regs, ulong epc, ulong *r_insn); +int get_insn_nofault(struct pt_regs *regs, ulong epc, ulong *r_insn); unsigned long get_step_address(struct pt_regs *regs, u32 code); =20 #endif /* _ASM_RISCV_INSN_H */ diff --git a/arch/riscv/kernel/insn.c b/arch/riscv/kernel/insn.c index dd2a6ef9fd25..c8f77c0093c9 100644 --- a/arch/riscv/kernel/insn.c +++ b/arch/riscv/kernel/insn.c @@ -2,6 +2,9 @@ /* * Copyright 2025 Rivos, Inc */ + +#include + #include #include #include @@ -74,6 +77,17 @@ int get_insn(struct pt_regs *regs, ulong epc, ulong *r_i= nsn) } } =20 +int get_insn_nofault(struct pt_regs *regs, ulong epc, ulong *r_insn) +{ + int ret; + + pagefault_disable(); + ret =3D get_insn(regs, epc, r_insn); + pagefault_enable(); + + return ret; +} + /* Calculate the new address for after a step */ unsigned long get_step_address(struct pt_regs *regs, u32 code) { --=20 2.43.0