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 772BED6DDC6 for ; Fri, 15 Nov 2024 03:19:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EDAF6B007B; Thu, 14 Nov 2024 22:19:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C48F6B0082; Thu, 14 Nov 2024 22:19:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88BF96B0083; Thu, 14 Nov 2024 22:19:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6B5736B007B for ; Thu, 14 Nov 2024 22:19:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F16A9141301 for ; Fri, 15 Nov 2024 03:19:52 +0000 (UTC) X-FDA: 82786873302.06.3E6E610 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) by imf18.hostedemail.com (Postfix) with ESMTP id 31D621C0004 for ; Fri, 15 Nov 2024 03:19:31 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=eIX4WQp2; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf18.hostedemail.com: domain of nick.hu@sifive.com designates 209.85.161.41 as permitted sender) smtp.mailfrom=nick.hu@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731640660; a=rsa-sha256; cv=none; b=HFzWQtmZ7FfCtQzOn1l2oP6seYt6rz7Myp1z46Pqnb3FIdfkWGTEDQS5+aqnRI7tY1CR/N YCuP+hdAPn4kZXSJn/F6un8HFbm+xc55tmGxXEGoJGCSmqs6nxz0sXz0We+FdYGKvWNI/E Krgt1iq+nBVYAyxNChIlMQ365dfJOZ8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=eIX4WQp2; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf18.hostedemail.com: domain of nick.hu@sifive.com designates 209.85.161.41 as permitted sender) smtp.mailfrom=nick.hu@sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731640660; 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=8wHT7UOLhFt9tb7tI16LMGdFlLAI81aR1dzrwfzW0EI=; b=E3aTPqW4TTtL5Tux0+btctLSdaoUkjqCtKlYXQ/L25ohngBiExUB/pwA1n8EhjCgP3ItXA vPThvKR4iNDNapa9Gle56MqyXyM407zRFHWMe1pYfNvHMhlYVMAcRz6460ZJmEPiiocjOc RETivI4eD3Y4ChRa/Txr8NcwHT+eKJc= Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5ee763f9779so740901eaf.1 for ; Thu, 14 Nov 2024 19:19:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1731640790; x=1732245590; 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=8wHT7UOLhFt9tb7tI16LMGdFlLAI81aR1dzrwfzW0EI=; b=eIX4WQp2MhtO0BS5BnFxnbZPjRhI86IvwQo4AuzshAtkg4MAmKPJTFa3ViyEPs8D6F DFXuvHsjPOT47yUnmhv5omWyKdjihtzzW33aM4OMd83YvuUiMsEO6Awdnt+uEP42ZCQN zzPdLEeI5qRgboJuH6FMb/qIvxuMeCCPYpRJ5Z8WHbSNSYnfhXPu6kATs1hcssAzGc2a ot9hiW0nkdrijyBWjZl9bOAAk/4QBK5t4NL7AivF8taiMTojd6xvn3KsHVsX9rmgUxOn 0XflK/Gg+RUlvq4RqTd3fkiTtD8hyrwBztUHXQrWUsf1SiBD48Uz92/Pnd+DHuNEp6sT L/OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731640790; x=1732245590; 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=8wHT7UOLhFt9tb7tI16LMGdFlLAI81aR1dzrwfzW0EI=; b=X5Do2394lJDeq2u2BGWZmhezCCHGg+QdBsHamorc4DQRPaa5WxIggvLyZOI3hbIVAQ oWhqUbidqh/5Nov6c/+1zPPTQ87q69FLy7gg/CXZYr8E+iqQ2tJ13dBcc7GcuRfptJ6v 0uP6Nt99nMzRBtZAZd9RutD2C9BvTtP9/Wy90ds5ukYrT6bHSHua11nCr6ReHbOdPlX8 3cKFBKHze6U5NyDibPvCAfzGOfa4PLI0J1xdAt3iDbgtCY3Wa48xdpCi9gviXY6tJjUs kePNXyfVaFaKJntwK1MgAfOMhqptDuO+inXe53ASvQ5/MCfcf0fhWV8YIvzdUjTkDT1i CzVQ== X-Forwarded-Encrypted: i=1; AJvYcCWVSW5hv239rpu1LKamAa+RWmLRwDj98aZs5OK8aUrMbwY+3LWyEr+xkHerMVPlBUFvcg3/z8uyJg==@kvack.org X-Gm-Message-State: AOJu0Yz22io+Hu/zrz1kBn9Pim8F9kxSbfvfZnRaQBRmgV+xGa3ixan1 jlEw8eR9v46zlpFyv2zlgVSNF0RGFnfSGfC26iLvack6BJfSlK/wT+mSqNN5WTR8fGQluEieo77 7ZDPCKQk1oZ6W09YAkIaIHgFaFQkYnbS37RR5ug== X-Google-Smtp-Source: AGHT+IHz3zxPQbbbUsepKHUF1uUsADOynrdvoPD0uimJS+ZQZoflzX/TbG/ec+1dOiYfpEXSQ93zscANzNpMS8LAAoQ= X-Received: by 2002:a05:6870:4d1a:b0:261:b48:3c99 with SMTP id 586e51a60fabf-2962dddcaa4mr1182864fac.23.1731640790020; Thu, 14 Nov 2024 19:19:50 -0800 (PST) MIME-Version: 1.0 References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> <20241111-v5_user_cfi_series-v8-24-dce14aa30207@rivosinc.com> In-Reply-To: From: Nick Hu Date: Fri, 15 Nov 2024 11:19:39 +0800 Message-ID: Subject: Re: [PATCH v8 24/29] riscv: enable kernel access to shadow stack memory via FWFT sbi call To: Deepak Gupta 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 , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 31D621C0004 X-Stat-Signature: asqe1gptidan74xrcnn7me5dg7ne1t61 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731640771-953127 X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zM25ayFGZKsgrKLjO1rwVbRaCSRqDmk+/BruRIFmK2sMqcSxlrQlJhz3O526QrIiAg+Gil5D3y43ZQQmHjkBc8ETzmxmDSSMEs+YPZqejyaI9XIysg683rhaHmrQoSlQoWrd2tg15ch23Ga7NVoEr75QvmjRTKzxLnJ/0Ppx8nOJh5p4NKrGrrlYxW43AFsJsatuJiDXBJlB2YIRMf22Q4QFXx7db/w42yeizX8pG4EQSzbGPYuhZAgI6p+atOSLMABpMyYaJYn2ti35VJAEF2cKXJ7fqUpl3+ptwTMXTrfiyKQVdUeMiicM 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: Hi Deepak On Thu, Nov 14, 2024 at 11:50=E2=80=AFPM Deepak Gupta = wrote: > > > Hi Nick, > > Thanks for reviewing and helping. > > On Thu, Nov 14, 2024 at 02:17:30PM +0800, Nick Hu wrote: > >Hi Deepak > > > >On Thu, Nov 14, 2024 at 9:25=E2=80=AFAM Deepak Gupta wrote: > >> > >> On Thu, Nov 14, 2024 at 09:20:14AM +0800, Nick Hu wrote: > >> >Hi Deepak > >> > > >> >On Thu, Nov 14, 2024 at 9:06=E2=80=AFAM Deepak Gupta wrote: > >> >> >> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > >> >> >> index 356d5397b2a2..6244408ca917 100644 > >> >> >> --- a/arch/riscv/kernel/head.S > >> >> >> +++ b/arch/riscv/kernel/head.S > >> >> >> @@ -164,6 +164,12 @@ secondary_start_sbi: > >> >> >> call relocate_enable_mmu > >> >> >> #endif > >> >> >> call .Lsetup_trap_vector > >> >> >> + li a7, SBI_EXT_FWFT > >> >> >> + li a6, SBI_EXT_FWFT_SET > >> >> >> + li a0, SBI_FWFT_SHADOW_STACK > >> >> >> + li a1, 1 /* enable supervisor to access shadow stack acc= ess */ > >> >> >> + li a2, SBI_FWFT_SET_FLAG_LOCK > >> >> >> + ecall > >> >> >> scs_load_current > >> >> >> call smp_callin > >> >> >> #endif /* CONFIG_SMP */ > >> >> >> @@ -320,6 +326,12 @@ SYM_CODE_START(_start_kernel) > >> >> >> la tp, init_task > >> >> >> la sp, init_thread_union + THREAD_SIZE > >> >> >> addi sp, sp, -PT_SIZE_ON_STACK > >> >> >> + li a7, SBI_EXT_FWFT > >> >> >> + li a6, SBI_EXT_FWFT_SET > >> >> >> + li a0, SBI_FWFT_SHADOW_STACK > >> >> >> + li a1, 1 /* enable supervisor to access shadow stack acc= ess */ > >> >> >> + li a2, SBI_FWFT_SET_FLAG_LOCK > >> >> >> + ecall > >> >> >> scs_load_current > >> >> >> > >> >> >> #ifdef CONFIG_KASAN > >> >> >> > >> >> >> -- > >> >> >> 2.45.0 > >> >> >> > >> >> >Should we clear the SBI_FWFT_SET_FLAG_LOCK before the cpu hotplug > >> >> >otherwise the menvcfg.sse won't be set by the fwft set sbi call wh= en > >> >> >the hotplug cpu back to kernel? > >> >> > >> >> Hmm... > >> >> > >> >> An incoming hotplug CPU has no features setup on it. > >> >> I see that `sbi_cpu_start` will supply `secondary_start_sbi` as sta= rt > >> >> up code for incoming CPU. `secondary_start_sbi` is in head.S which = converges > >> >> in `.Lsecondary_start_common`. And thus hotplugged CPU should be > >> >> issuing shadow stack set FWFT sbi as well. > >> >> > >> >> Am I missing something ? > >> >> > >> >This is the correct flow. However the opensbi will deny it due to the > >> >SBI_FWFT_SET_FLAG_LOCK already being set. > >> >So the menvcfg.sse will not set by this flow. > >> > > >> >if (conf->flags & SBI_FWFT_SET_FLAG_LOCK) > >> > return SBI_EDENIED; > >> > > >> > >> hmm... Why? > >> > >> `conf` is pointing to per-hart state in firmware. > >> > >> On this incoming cpu, opensbi (or equivalent) firmware must have > >> ensured that this per-hart state doesn't have lock set. > >> > >> Am I missing something? > >> > >Current OpenSBI doesn't clear the lock in the warm init of the hotplug p= ath. > >It seems like we need a patch to address it. > > Got it thanks. > Since you already know what's the problem, can you send a patch to opensb= i. > If you want rather have me do it, let me know. Thanks. > No problem. I'll send a patch to opensbi. Regards, Nick > > > >Regards, > >Nick > >> >Regards, > >> >Nick > >> >> > > >> >> >Regards, > >> >> >Nick > >> >> >> > >> >> >> _______________________________________________ > >> >> >> linux-riscv mailing list > >> >> >> linux-riscv@lists.infradead.org > >> >> >> http://lists.infradead.org/mailman/listinfo/linux-riscv