Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp804151lqp; Thu, 21 Mar 2024 16:51:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVdO/w1viq+ylzaoV3/embN2ce7OLlxFY/wjHd2eBek/BdD6I8FltgAkdFHkEAlA0KR0rBjTzGEsXlBA3aD4yrekAmUsWd+4cuLHEpqSg== X-Google-Smtp-Source: AGHT+IE0fU8SE8U68uqKyyqjqNn7gZoD6CoXp+2nTg7a75+PE3PLas+D49s8qUoK/owyKsBjxK2I X-Received: by 2002:ac8:5894:0:b0:430:ce90:5704 with SMTP id t20-20020ac85894000000b00430ce905704mr785431qta.51.1711065104943; Thu, 21 Mar 2024 16:51:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711065104; cv=pass; d=google.com; s=arc-20160816; b=rDE39AUgSDm3uCauyXKp1aZnQHAB52+m4STENskcpTFk8Ishpwuo2Vs/km50HphGAy +HntQbVSofjq1R98n8a0cCAwmtsVS3VXd7rU+NgeRtJ5jgzxTcU66ihnWeyogKDCvBjQ 9a7nnQp9ZpypfC6qLIaBcAYNlLGR5UI2m4bxnc93Q1JjN7aA+nkyesRMp/oZc7Ybl6Lk zQKGhjc7geO8dRHxwTw1xA29wnp6/snz3j84VY178GVu17waMD1a30D4nW7E+YwX54qm mMBoiL3kcsa8cdsjoOWYmh+5cyW65EeClhia7iU+KwN4BaM111ln0Cq9U7hQc1ULXZhy mhMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=ZNqlzzs3C3okF1Ihs4S4kvN5WrFgjE+GlyvdPE0dOGo=; fh=2iWjqTpk205volaj3V68+4k3EmWU+iKBR0DmgK/9y40=; b=yqZSFpQDJU2joGdXfjYOLNcD9aiefZGmt1u4cnD1shL55aRoZl//jtyEvOS03L2fMy jUnm2s21iHtdoLVjeyxtj9Ou5z5+2uM5yAucdNvRUFUy4/ogfdWa8lIrjnp5k5y+rN/j StRUktxbmmpqvA/+vVLPF0Q90XTbSHEpI0Am9yaytKpNEPORIcs5zk5oq8Pi8QWtNZYk piT9eh9AADuelnmxaFC1EGWKiGW3SSzP4TwpibZT7OxFqMdSp69dhfQKmYeVCL9QJJ5A yeaSk50p7engCk7Xno1EamTm1em3sfp72g+DBPdFO1pwYvwqAB7ASO/UQ7K3glzcnEAN PUuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DP54qrRT; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-110801-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110801-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z6-20020a05622a060600b00430d6ed8524si869676qta.605.2024.03.21.16.51.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 16:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110801-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=DP54qrRT; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-110801-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110801-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D9181C21BAD for ; Thu, 21 Mar 2024 23:51:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 202A43A26E; Thu, 21 Mar 2024 23:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="DP54qrRT" Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) (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 E52691DFD6 for ; Thu, 21 Mar 2024 23:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711065098; cv=none; b=t3JHEevhb055x2G8/9fIM+LOEVagnfNfjVfxQRBY/VwwKnFaYuH/wlvAdhF+82e4IEBT90rzUDNJw5nIFWr8WXBSPvYrEKlAskuyo8Kmm4wxJpd05ujQAi5Iv/lwTGpgemLP4uU6ry9N83LWUxcxfGttFxE4ZBI3lX4w9Ws7Z6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711065098; c=relaxed/simple; bh=xW80rWOlFHvVSoFt0FE2CMnMtCrSafEX4MbK88/mY5c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Zz3y8l8zsjUzwBdZ5NDsE8gAFNWooDh6iDZAbvZuiASoPUngtm/w9aX3VcKPlCDtWkqT9MTX2AhKaadfk91rOO9Yro6NTwRE79sY87DtGpg/7OXvQV36+PkAyy//gInDa0iFJBUG7Ody6ZWK4xmtrKxkh5cqlgLMj/oimHf0Q9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=DP54qrRT; arc=none smtp.client-ip=209.85.166.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-36867dfe940so3581115ab.3 for ; Thu, 21 Mar 2024 16:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711065093; x=1711669893; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ZNqlzzs3C3okF1Ihs4S4kvN5WrFgjE+GlyvdPE0dOGo=; b=DP54qrRTYYqyASdalC9kq72lU1wWtpzCs0Ru7p2AHu1ONctSNu140YEjzlXpuGOnuI D1zDB17CJXnYj6A+WEcunVteD1yJHvk8HWstDZ3ZU/u3jhLJnkE7rU2ZkuxpB+6EcX8O AQGon8LDmL3+iO54Z85lNqRzZVMUbyu6Zz/2OsQYp60Ex/8TUCDPf+kFIEa5stLAvRWG OxrcMw4NCAEtwAYHcOnjmwD+FcyhDXx1RQMt9RYhSY7pRrfc3jblIjmVvsxZr9sj2mTE kyWH9a/wlYrFivg5+IyRnw/4er9qQZqFB3T1nxeO2EiERw0hP+Gf7o256gW7LmshCoAL fHjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711065093; x=1711669893; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZNqlzzs3C3okF1Ihs4S4kvN5WrFgjE+GlyvdPE0dOGo=; b=SAYN+7MUeDXELogT9ALtt0y8tFMfXStrfiKK/F2QkxYTKbDL+2JAcgY11biRZzva1r FF7XmI+EEtXYuI+86Vc1lK0DTeZfbgwV57f7YecBgd2+uF2JSwF0A2s3aQ4EettWZxEP R1K4SxjUamIf5+6t8S9lj0nrfyVQRP72HNsRuQ/a/wRsdsjP8aoG15inNfZHM7Pi3Dqj ar9Rrz9ezb0bVyuthoET9zAImM37qDRO7huAw6q1Xz4uSjNFcXlEF98PzDVHW9IXoSYm 0s3O/sJcs/r8UESmsylMwdEOu3UwHTYPbW4nfz4VAjbB7oRd7UUd8BUQpfXYeNSGdIbE wRVw== X-Forwarded-Encrypted: i=1; AJvYcCUhhwCpEG5c+2NMDvJ+VOTr5y0Qqc8NKehJnB4w9kWw/J+8l1ycYRkcCz2+nf5TOqwY9OpUIrJqdoFHnLwD+JnaffnOJu0zIhEqoGsU X-Gm-Message-State: AOJu0YwrpBfGQXpuTLIWunCI68Vjc15eXj8SEGYQhreojtGoHltqVVXq WLsZ6585KA4bHTW4kYOZ2sDeDHCh8ysT5kKSyvdWKWUkE5LOh/HpJ/bT469bTnQ= X-Received: by 2002:a92:dcce:0:b0:366:40dc:4d99 with SMTP id b14-20020a92dcce000000b0036640dc4d99mr986208ilr.30.1711065092945; Thu, 21 Mar 2024 16:51:32 -0700 (PDT) Received: from [100.64.0.1] ([136.226.86.189]) by smtp.gmail.com with ESMTPSA id t5-20020a92cc45000000b00366b66af14asm237709ilq.17.2024.03.21.16.51.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Mar 2024 16:51:32 -0700 (PDT) Message-ID: <3010bb57-c13f-494a-9e8c-0ae6393b1eee@sifive.com> Date: Thu, 21 Mar 2024 18:51:31 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] riscv: Do not save the scratch CSR during suspend Content-Language: en-US To: JeeHeng Sia , Palmer Dabbelt , "linux-riscv@lists.infradead.org" Cc: Albert Ou , Andrew Jones , Conor Dooley , Leyfoon Tan , Paul Walmsley , Pavel Machek , "Rafael J. Wysocki" , "linux-kernel@vger.kernel.org" , "linux-pm@vger.kernel.org" References: <20240312195641.1830521-1-samuel.holland@sifive.com> From: Samuel Holland In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024-03-14 11:55 PM, JeeHeng Sia wrote: > > >> -----Original Message----- >> From: Samuel Holland >> Sent: Wednesday, March 13, 2024 3:57 AM >> To: Palmer Dabbelt ; linux-riscv@lists.infradead.org >> Cc: Samuel Holland ; Albert Ou ; Andrew Jones ; >> Conor Dooley ; Leyfoon Tan ; Paul Walmsley >> ; Pavel Machek ; Rafael J. Wysocki ; JeeHeng Sia >> ; linux-kernel@vger.kernel.org; linux-pm@vger.kernel.org >> Subject: [PATCH] riscv: Do not save the scratch CSR during suspend >> >> While the processor is executing kernel code, the value of the scratch >> CSR is always zero, so there is no need to save the value. Continue to >> write the CSR during the resume flow, so we do not rely on firmware to >> initialize it. >> >> Signed-off-by: Samuel Holland >> --- >> >> arch/riscv/include/asm/suspend.h | 1 - >> arch/riscv/kernel/suspend.c | 3 +-- >> 2 files changed, 1 insertion(+), 3 deletions(-) >> >> diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h >> index 491296a335d0..6569eefacf38 100644 >> --- a/arch/riscv/include/asm/suspend.h >> +++ b/arch/riscv/include/asm/suspend.h >> @@ -13,7 +13,6 @@ struct suspend_context { >> /* Saved and restored by low-level functions */ >> struct pt_regs regs; >> /* Saved and restored by high-level functions */ >> - unsigned long scratch; >> unsigned long envcfg; >> unsigned long tvec; >> unsigned long ie; >> diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c >> index 299795341e8a..3d306d8a253d 100644 >> --- a/arch/riscv/kernel/suspend.c >> +++ b/arch/riscv/kernel/suspend.c >> @@ -14,7 +14,6 @@ >> >> void suspend_save_csrs(struct suspend_context *context) >> { >> - context->scratch = csr_read(CSR_SCRATCH); >> if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG)) >> context->envcfg = csr_read(CSR_ENVCFG); >> context->tvec = csr_read(CSR_TVEC); >> @@ -37,7 +36,7 @@ void suspend_save_csrs(struct suspend_context *context) >> >> void suspend_restore_csrs(struct suspend_context *context) >> { >> - csr_write(CSR_SCRATCH, context->scratch); >> + csr_write(CSR_SCRATCH, 0); > If the register is always zero, do we need to explicitly write zero to the register during resume? The register contains zero while executing in the kernel. While executing in userspace, the value is nonzero. The value is checked at the beginning of handle_exception(). We must ensure the value is zero before enabling interrupts, or we might incorrectly think the interrupt was entered from userspace. We don't know what the value will be when the hart comes out of non-retentive suspend. Per the SBI HSM specification, Table 6: "All other registers remain in an undefined state." Regards, Samuel