From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 E543043AB9 for ; Fri, 7 Jun 2024 18:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717786272; cv=none; b=YuyrpQi6gFL5QcDR+/CgnZ3YdUCWy6w9oVWn1muFJgqw8VEjNBQzC0IStDauS6gt58XIMCJOnIS7/4ZFcnefwqIKe0RReUNHz3lJ+A442XC4wKghUN7VHIGaUSvvktD43sDB4zj5Kc8HdXb8juHKLkwN4cOAnFtJBFw1w1Xsjro= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717786272; c=relaxed/simple; bh=spdlnQosYbgxz0z1aI+nHwJdAm4uQJgtsueSAk82Hto=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I8mSJA7e0tU7Ccm/5W0XVZv+SsQWoWZ60ZNhNUPjvCgcb+EE7IuiibUCPLUtNytKRHOFtHVj5f+VkAGvWi6XuwoD3SuARr8XjIa+7wJ4TfsneOLtIgeN6HCLAekXnG+QI1Tx31aYSz+1M6oQBmj5gfDQUISzVygze4PfZT+mMrQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=hgLGbMPf; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="hgLGbMPf" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f44b5b9de6so20779245ad.3 for ; Fri, 07 Jun 2024 11:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1717786270; x=1718391070; darn=lists.linux.dev; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=spdlnQosYbgxz0z1aI+nHwJdAm4uQJgtsueSAk82Hto=; b=hgLGbMPfyTHz7gZbtvjFesKTTrT+zV1jDAc6eYHK8z10oBBwAgp274YKqdjq5QS58h 13WecgH4FtRM0cYrr7duuR0jNn0Ifo6NpdyC6K2yPNrB0Xj56Svxnefmf1T6dhNn2NVe DvrCDrtRwHNnX6KfmY+LPlkSUXOfDmNh3+AX0KufPArDmsiQI2zRlcgi1w3cHp76aMjO opNu7sq5osdOj8aunyRfxThpDO336RqvUmDkSPhDTmtNXfgrWNLQXY1+Vfooqam8ZcCG UMCDe4wZDJnPHNbz4YpR3J8Pd47TVZ9GAEDbGzy77bcT/WmxJ1ynei7E9ZR/VMd0QsMN dmZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717786270; x=1718391070; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=spdlnQosYbgxz0z1aI+nHwJdAm4uQJgtsueSAk82Hto=; b=RXEK5eZOUI/2lOz1h9YjyMzhlZasSDIBnQqGkqXVGBtwWMvAkqo92Xf69LW9B3sV5g ey/LTZeZMDlUJEczJ1oWOd2Nwyif9X4v/NZfNc4m8s3gvyuH3hA88qJYGoGZjTe0ru+O FXfQEySelMLyp0J+7zXCkirGoO6/d0AlKAiBMJFHDwv5DRpxj3QJ53O/vkD+u9TGcQjJ MfMHGcsCP/64XoqsNGf4SEu86Ks46Hxwk0IA67MElURiUI5VSIst/MgneDYv9b4dM/C2 zMphh88s7IsVMtPP4kEk+GH9q48mSeCt9UZT/YUCObms9doL5jA1t/nd2tw1ALJDX3aw i9Hg== X-Forwarded-Encrypted: i=1; AJvYcCW/aa7SmqMpaDmY664KNL+FTplGSbKw92S9/e8K9DLLYMOpExNZ9QR2djmIOHa954+vipN4kI/XJGmJlQDSmEQX5MI1Bg== X-Gm-Message-State: AOJu0YywGjYVcyClnIh+PjfKR2sg4hx3kK3wGzlO2w8fvJnCMAKL7HRy 21/qpqXJCIG8Z3xAI24skGgJdGT4HtkQs1bHxIbOQ6rcZgP+KHpbLs+qqZhRie0= X-Google-Smtp-Source: AGHT+IGMjAuAS3XI2gD8/NyTDV8hJlKEUmolHeTNHvKFVpM0ZupPk3AuvNMIhwwVwTDX8d6lLV85Cg== X-Received: by 2002:a17:902:e887:b0:1f6:8081:6818 with SMTP id d9443c01a7336-1f6d03c0e1dmr36550955ad.52.1717786270083; Fri, 07 Jun 2024 11:51:10 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6ea2d17c5sm7512365ad.46.2024.06.07.11.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:51:09 -0700 (PDT) Date: Fri, 7 Jun 2024 11:51:07 -0700 From: Deepak Gupta To: Conor Dooley Cc: Alexandre Ghiti , Jesse Taube , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Alexandre Ghiti , Palmer Dabbelt , Albert Ou , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Paul Walmsley , Nathan Chancellor , Nick Desaulniers , Masahiro Yamada , =?iso-8859-1?Q?Cl=E9ment_L=E9ger?= , Atish Patra Subject: Re: [PATCH v0] RISC-V: Use Zkr to seed KASLR base address Message-ID: References: <20240531162327.2436962-1-jesse@rivosinc.com> <20240531-uselessly-spied-262ecf44e694@spud> <20240603-stinking-roster-cfad46696ae5@spud> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20240603-stinking-roster-cfad46696ae5@spud> On Mon, Jun 03, 2024 at 01:47:40PM +0100, Conor Dooley wrote: >On Mon, Jun 03, 2024 at 11:14:49AM +0200, Alexandre Ghiti wrote: >> Hi Conor, >> >> On 31/05/2024 19:31, Conor Dooley wrote: >> > On Fri, May 31, 2024 at 12:23:27PM -0400, Jesse Taube wrote: >> > > Dectect the Zkr extension and use it to seed the kernel base address. >> > > >> > > Detection of the extension can not be done in the typical fashion, as >> > > this is very early in the boot process. Instead, add a trap handler >> > > and run it to see if the extension is present. >> > You can't rely on the lack of a trap meaning that Zkr is present unless >> > you know that the platform implements Ssstrict. The CSR with that number >> > could do anything if not Ssstrict compliant, so this approach gets a >> > nak from me. Unfortunately, Ssstrict doesn't provide a way to detect >> > it, so you're stuck with getting that information from firmware. >> >> >> FYI, this patch is my idea, so I'm the one to blame here :) >> >> >> > >> > For DT systems, you can actually parse the DT in the pi, we do it to get >> > the kaslr seed if present, so you can actually check for Zkr. With ACPI >> > I have no idea how you can get that information, I amn't an ACPI-ist. >> >> >> I took a look at how to access ACPI tables this early when implementing the >> Zabha/Zacas patches, but it seems not possible. >> >> But I'll look into this more, this is not the first time we need the >> extensions list very early and since we have no way to detect the presence >> of an extension at runtime, something needs to be done. > >Aye, having remembered that reading CSR_SEED could have side-effects on a >system with non-conforming extensions, it'd be good to see if we can >actually do this via detection on ACPI - especially for some other >extensions that we may need to turn on very early (I forget which ones we >talked about this before for). I didn't arm64 do anything with ACPI in the >pi code, is the code arch/x86/boot/compressed run at an equivilent-ish point >in boot? cc: +Clement and Atish I don't know all the details but on first glance it seems like instead of ACPI, may be FWFT is a better place for discovery ? https://lists.riscv.org/g/tech-prs/topic/patch_v12_add_firmware/106479571 Supervisor could query if Sstrict is implemented and then it can check for lack of trap on CSR_SEED or straight-away check for presence of Zkr.