Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1236332lqt; Fri, 7 Jun 2024 11:51:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWn8Q5cBTUfUt9nctmiTST6r+wkzqLG2pOsJOXZnvWPz4rJ+s0jtb6PDIlGa4v/6lPI1gSsd02UancAjqKKdufHkpjLL1/0aqQ5ZuDixg== X-Google-Smtp-Source: AGHT+IGRPwPIO4z1JQMXi+uqCsK9T5QXq5YiwFTlEhcKJ7TkjUD1nXFNB8ptfUaSIh+ZLLeZGoKK X-Received: by 2002:a50:d702:0:b0:57a:321f:cc4f with SMTP id 4fb4d7f45d1cf-57c508fa665mr2026606a12.19.1717786281283; Fri, 07 Jun 2024 11:51:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717786281; cv=pass; d=google.com; s=arc-20160816; b=FKtmegQlQiBcQG80e+16+cxI6A8LCXhgBZxpxMh348xUR7u3hnMouS8A77k4V7l06C D10jjITg8z6J94j7f6P+FxL8+1R1dalHgS3kjWbZio8HK+7uL8CJ0wuh8cX2tw9L0Jk2 Sf2Q5LPdePLFgX5SDgw6c3A3l+M5DjLs0yFgFwjO37Lxvl68g0ESeU4NJKPSz2xbkj9k aSJfvK9IFeSxj/ZwfqytYfCc5vLtGZhTY2lY54mx4M0rJiwTEiwESHAxuKPsOppKNZka i9LGoIxEyTpVh3g8/G5DuDFf7sXCoW6Oou/7TcjMtzn9Av90uvdzrd27ZXJALb0775Ba wiVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=spdlnQosYbgxz0z1aI+nHwJdAm4uQJgtsueSAk82Hto=; fh=Ixx/EZgoODXUoLCk1bs59+ZMq7sDzjR0HL1KUH+9MWw=; b=DfRiRtQP1Tgdnl4vobRYOJer063O5B+cqrx/BzXPFdB7pZ7IHK+FKpPC4bLCmQmHDF VatWjGR6Hv4hSEsH9WNvgC3orTl1F1wp8wBRZrkTJ+6qVPMKTPecJyKDjaKZDWzY9mOI zddoHALIjYtlUuxoXLpQeklE2J7e1ylM+WZ8jo5WUMF6lx3wVS67vkBcm78TQFNaHzcD 6ujZtiE0N3RN3kF8kppHNJ0o1yPQJII6nPFtgyD4siVIXWeV/yaFzsLq5hcILi1PG2/i blfwgzCj29Qpm89FppEzt8hnQ7uqFhvyQOEVkQiFdKwcU4fRAEwU1o1EJ5vD7j8KXFyU qpzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="WFw1/GNp"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-206611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206611-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c5fcef6e9si628789a12.542.2024.06.07.11.51.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 11:51:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="WFw1/GNp"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-206611-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206611-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C3B091F22ED9 for ; Fri, 7 Jun 2024 18:51:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5764A13F440; Fri, 7 Jun 2024 18:51:13 +0000 (UTC) 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="WFw1/GNp" Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 E268510A24 for ; Fri, 7 Jun 2024 18:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717786272; cv=none; b=S7jMKIrOTA6PVSO415LK9BUabeMO1nsOSRWTtVCAOJNg3EWtN1png0QtCuhmG9ZiyRqYGzmBh0B9N36NRBqsXqZi3OSnbj55XEbHI50TItlRigQwNZwrT6LG3E5yc5w+IUJuU9vKXBheVscl3+sXaVYMfTSDM1Fv8SmWAZ3ejW8= 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=WFw1/GNp; arc=none smtp.client-ip=209.85.214.169 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 Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f47f07aceaso22000505ad.0 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=vger.kernel.org; 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=WFw1/GNp9FeBe4ASe4EDPLuFie7nG9LNLf4G7KoAwtK0dNqDYH6hHOl5BXTsBoFcCf ex7qGv1TQY8+NocTH5r9/Ry75oOPxUjMvuyKGRAKTdx3Z/9xPhiPOfF6BXaINr7XGX+d LhI1MjymNXVJYdcAAp4RIzUAcitke7jJbRcCuoXJeV62AWFVfVGiyuAefzg+vSQ4QQe9 rV9FHByZQYj5s2OFzJSjrArFdQMj/419yAkc6FEvbtvUOo9m0q2lbRX4iFLgWwPUQ0lW 8Z1HmLWwyBPuqBDsFQS6ItmjN277sgfz6lRERSPOYxfX8gan430YZ5HdSMS8eMACZicC vfnQ== 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=tYvBJtdBD+V+KlJJZQJa6aUxpIF1ajPRPhvc4qVy6m1Aae9MuWth7kZ31JrFANcu1B uCKbDdO8OqwV8IhymYM32J03BoIrGZbEqpw7eUdL7GNedVSCbH0Lh6K9k6IflWEZxLRF 94j42UdHyGNlW97h8yeE4Aq9x9tFmZZaQtjCoQyQ9YL88+28q7WqyzgdDnYJmV6KfkVg 1ORMZ7ysgTzdxeYEj7Znl/oYIWJzAIPOFH7Hg0BJILCdybxsS/Vm1sYYBNSwy3xliUEz D75mNOIIHx3dZ/OITLIWK9YfD4Xezt2VD+WP9/phC1aWF2+7Ow6Z/T7KNZjQjSLRlP8Z +yUQ== X-Forwarded-Encrypted: i=1; AJvYcCXShDKqxkq8MnNoqOVY7aBaMhCusvrNVn9skmB0rR2KWjY8g3KaaJXKZFwu7sEg9ZJQZRXeBxeH3iZCjGpCGBjNJBEMY7PvIvudi50k X-Gm-Message-State: AOJu0Yy4oTkAjQG6ALJCqZ4H5DxbnfzVstLSXEPljJ1YauvMG21VcizQ F3JIFjaBu5PfPBlG3LW15PJrrQYdgc+NDkVPpg/+638m05mqCoq8IQRH2fzJvbQ= 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: linux-kernel@vger.kernel.org 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.