Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp511088ybl; Wed, 14 Aug 2019 01:25:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaaj31uwOO0i6Et6kuoEhVMHhcjLdwV8ZhTEBTlwRrzRhp/NzwPsv5VRtLWff7OXeSOmYb X-Received: by 2002:aa7:8746:: with SMTP id g6mr6534376pfo.191.1565771144878; Wed, 14 Aug 2019 01:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565771144; cv=none; d=google.com; s=arc-20160816; b=tU145+1SyfHjSnfY9eQP8QtEvuQNS8ojq7nAKSzBBakhcI7/NKuT5T3nwoeQS/7U6H +4fF4N+U4VZIAEgiCTySjTWktUo/CQGTL8bqSj9inWK7vIC9d4CMFOLmEjbB9eblADqh eGbcvFNsMMOJJB4GukzCKptX5Q+8Gvza7NH29DOt7zvkDGe+mFsFoaQMBEpaaMgOEGxG ywTO+Kp+2aUIslWQNfeIPomBnidh0osj2AZfuu8dSEKBRlJnpEH5TkrIuUF6ueSp7ogm qJzr290Yyuz2SbLM+H1p0Rk2cnCHshWy/tldGC5WKsoqvC7b3QK18LB+TAA3y+XO23ur SWJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=rEnxligpiNBOZsMLUa2pNExp9uwlDBDh1X2nlxPgNEQ=; b=UWihqMODIeDknPO5mj9bm+i6D4AmBukOWRwBmsOTMHf3yli8ZMgh+W8V124t93wQi7 Y9Lt723cFFaHFOt1fox0RlI6ykOJtHuC3lTeZ79Ho5CnGMQzVfTr/5o+ZVnjV+qvc0Xq FOmWP4x83yUrPbWHiRhuu09HE4XEthht6/JX5mrW3wmXo5blxFnTZPxOnZhMfyxyJCBX FW2+7FU8nMTab5ngh+mc1/v+ICs2j66iwc0aIPakytvlmgdL9uc9HeusxNEJ0ip1Cpv1 tH5zgwi/1UV+VzrS6Y0gzXaYwtcpZ4l7BV0EFJad+UXzwmOAFwu2bULuol/fUlDNEDYa sh8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=SHwQE8pQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28si18411985pgk.331.2019.08.14.01.25.28; Wed, 14 Aug 2019 01:25:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=SHwQE8pQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726875AbfHNIX6 (ORCPT + 99 others); Wed, 14 Aug 2019 04:23:58 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45846 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725265AbfHNIX6 (ORCPT ); Wed, 14 Aug 2019 04:23:58 -0400 Received: by mail-pf1-f196.google.com with SMTP id w26so7874190pfq.12 for ; Wed, 14 Aug 2019 01:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=rEnxligpiNBOZsMLUa2pNExp9uwlDBDh1X2nlxPgNEQ=; b=SHwQE8pQnfcqX2bqOvsQmD1HbXJdaoQyGKVRNZ6z+tUsJ4fLN8rXLNYxl+X0JlDsyK 2kMaM/lMOc2xXiA/h9VnxbKLHQ2gWvjkoQ/Hxq3aTj9keLxc7+nlkxayPp6+KCRkxkBV MlTYkxHIXaoI/9rjFnQHyzaYAy3jiCv7KvwDgUCj5+yKqIHaMbr6PdF1YDF7xj18NIvR D76atVZQ8oLil0d+Z50nclSbSAebyq+kJHGoPCcS0jalYGtQ9gss3k2lavJdFFPo4cQE 7zq2rpa2XGm7daqS70jw/TtoSV8CU6RV9FqTFHNOH/NtOczod4yYn7r6cju4xr0gbMeq 6ujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rEnxligpiNBOZsMLUa2pNExp9uwlDBDh1X2nlxPgNEQ=; b=J/pLQzW9eVFoWRikV1aSMjub7uT/S/iN1duMRLT9bboZRPnJ3pwAzq7K1Rj4IOCn76 +SsINlLT8UtHEib2royrGKrWTyYyWpiAG5KqoA3PTZGExmHC3wvQdzej6Xksw7aQVumI Uv+tERJLcWFitTYnp3rYOTdxGG4vz3I/KvRG0MDt9TSRYAB0x5ZHNDogH5dmZtGPRNb6 GFsg2kHrJV0jfwdzHxasd+d2dw6f8GhvdXbMpEAfikblrVOhVdna3IclkQERSsodSkaa 7fwX9O/YE+aqW9OV+LAnz+xg3pVQATWKiOBIBC7QpPz8ypXCzE4RUDfNi3pFtK/bsiTK n9Pw== X-Gm-Message-State: APjAAAVnb/Q5jGiQcjXL13+0bWFRz1fIUlRLkKqk0w/C7UPStyFrV7d/ c1JPZN4m2rpb/igFTkC/YePxgg== X-Received: by 2002:a63:2c8:: with SMTP id 191mr37355432pgc.139.1565771037551; Wed, 14 Aug 2019 01:23:57 -0700 (PDT) Received: from localhost.localdomain (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id f205sm12359152pfa.161.2019.08.14.01.23.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Aug 2019 01:23:56 -0700 (PDT) From: Vincent Chen To: Paul Walmsley , Palmer Dabbelt Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Vincent Chen Subject: [PATCH v2 0/2] riscv: Correct the initialized flow of FP and __fstate_clean() Date: Wed, 14 Aug 2019 16:23:51 +0800 Message-Id: <1565771033-1831-1-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following two reasons cause FP registers are sometimes not initialized before starting the user program. 1. Currently, the FP context is initialized in flush_thread() function and we expect these initial values to be restored to FP register when doing FP context switch. However, the FP context switch only occurs in switch_to function. Hence, if this process does not be scheduled out and scheduled in before entering the user space, the FP registers have no chance to initialize. 2. In flush_thread(), the state of reg->sstatus.FS inherits from the parent. Hence, the state of reg->sstatus.FS may be dirty. If this process is scheduled out during flush_thread() and initializing the FP register, the fstate_save() in switch_to will corrupt the FP context which has been initialized until flush_thread(). In addition, the __fstate_clean() function cannot correctly set the state of sstatus.FS to SR_FS_CLEAN. These problems will be solved in this patch set. Changes since v1: - Remove unneeded braces - Remove unneeded ifdef condition - Make the correction for __fstate_clean() be a RC fix Vincent Chen (2): riscv: Correct the initialized flow of FP register riscv: Make __fstate_clean() work correctly. arch/riscv/include/asm/switch_to.h | 8 +++++++- arch/riscv/kernel/process.c | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) -- 2.7.4