From patchwork Thu Dec 21 07:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 182019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp235253dyi; Wed, 20 Dec 2023 23:08:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBMywo68rJlcU7eQwIwwTgAKyJDmrvuDgzrq9oVGAW7rCXEmXfqEpgMnv2rp96aR9Co42Q X-Received: by 2002:a05:622a:1ca:b0:427:8aa6:80ec with SMTP id t10-20020a05622a01ca00b004278aa680ecmr2957020qtw.34.1703142516059; Wed, 20 Dec 2023 23:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703142516; cv=none; d=google.com; s=arc-20160816; b=WPfoEURx+T6Fkrm61A3K/pdzG3kM7j0xS9HLJ9EQlGeIeC5rIGIb9WNQf3ZLpimLW4 EPozQTmLLlcV8s12DmtzO+sjG3357/V1noRxGRkVnNfmTOiLyi9Ei2X2erE13NT4hLnQ 4llT3fpfAcOPwt2wA1erlF8+OMY3wB8koxCrWEjNZR+RwDS1uyRlfxJMypQ8tKOX1qhF DMeNHrjkcPkSUJs5N14eQh0dNzBI9Fqfw3a6i/VTmjwDeriXedBSN7Z5kQfPK5r7t+fE EF6Z8KjIqY6iisSSbV7qCNlzpqHS+1hC+QYBLv9hZXX4hIsmq2mbHeF1MK9AB302GteP cjXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=2kCpclMViSGlwXrSv3CtFtlNcJ4mho2Ep2ftdnuTju8=; fh=LcwsEwUc0nskXWIisAZlnFARUuQjme5qsFxrcuddZeU=; b=diWUBYHb+5XSQmhnGEMxZxPaMfyU6XHlKe+X+HBlbICd8gdzb7O4JudhJ8QO/gnKGV nzwsLwE41eeNdeJ9RWEDt6kvYxlP+oTPAl9xgO1OPQQJQ91DW0Rxn7gUKFXwZHFExJEr kWY/A5yE/tTTGbDIEV7NCm5hVJHs5djdoZVychiykG4VYDmf7YDQMtbxeMka1WJWw7om vV4CQ9lO/BbvzV63Ugu/Vm3gMnjDwOQ13EiWleliDXXA2dM79TrygryWOHdH5/DjW0DD /5pQbNga18gv1fucRe6K+KsHRH6RBwM4QHbADB0yDoXVGKAoJCYH0a6BubT8KhuqA6ER GVWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v17-20020a05622a145100b00423735315c3si1576575qtx.179.2023.12.20.23.08.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 23:08:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7917-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B09E31C22B5F for ; Thu, 21 Dec 2023 07:08:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11EC414AB5; Thu, 21 Dec 2023 07:08:21 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4881114F8B for ; Thu, 21 Dec 2023 07:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tinylab.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tinylab.org X-QQ-mid: bizesmtp72t1703142306tblaxfeg Received: from localhost.localdomain ( [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 21 Dec 2023 15:05:03 +0800 (CST) X-QQ-SSF: 01200000000000B0B000000A0000000 X-QQ-FEAT: 90EFqYDyPxDH2HniTLYrCGVM0lzrYT3J1RBkPF9OpvfqEomvd8LqAX4a2tFyP xSskE1SPFeB1dab/nMJmmyK4Y9eJfkhfxTN0p1KXoy1nOMYslvqKxIyVlwSEdJqNvOCLDKF XgQjKtBH6p+699LlifhZnx/2Idjh20GPiIVkwyMC/YeBMf+kAXAMnlTWMAGy3JthyNUPf4X Ft7TWogOJrWFV8LOOodC4XwVZntDYS2OxioYlfK5J/FJ2gHyayBMBSZyYpwv8pqHwalauHu JXdc1ul8HXjoERHkBWfjEK+Gnx8f1iQEs/0MrQwSOarrEwGRQYFUSBTCh58CrslSZtFUWVB /kU/RXtpsjPVKXkEIjE2v9uqMsUT7k08Os/cDOx X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7023690611978233006 From: Song Shuai To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, andy.chiu@sifive.com, greentime.hu@sifive.com, conor.dooley@microchip.com, guoren@kernel.org, songshuaishuai@tinylab.org, bjorn@rivosinc.com, xiao.w.wang@intel.com, heiko@sntech.de, ruinland.tsai@sifive.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: vector: Check SR_SD before saving vstate Date: Thu, 21 Dec 2023 15:04:49 +0800 Message-Id: <20231221070449.1809020-1-songshuaishuai@tinylab.org> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz4a-0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785874366668850137 X-GMAIL-MSGID: 1785874366668850137 The SD bit summarizes the dirty states of FS, VS, or XS fields, providing a "fast check" before saving fstate or vstate. Let __switch_to_vector() check SD bit as __switch_to_fpu() does. Fixes: 3a2df6323def ("riscv: Add task switch support for vector") Signed-off-by: Song Shuai --- arch/riscv/include/asm/vector.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 87aaef656257..d30fa56f67c6 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -190,7 +190,8 @@ static inline void __switch_to_vector(struct task_struct *prev, struct pt_regs *regs; regs = task_pt_regs(prev); - riscv_v_vstate_save(prev, regs); + if (unlikely(regs->status & SR_SD)) + riscv_v_vstate_save(prev, regs); riscv_v_vstate_restore(next, task_pt_regs(next)); }