Received: by 2002:a05:7412:a9a3:b0:f9:93eb:408e with SMTP id o35csp62630rdh; Wed, 20 Dec 2023 23:08:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEX19TqLcPFsZ9MH7I9gFEJ2BNZWobaSpR7v9/5gp3RlW1lZ47u6QdqA4l5xUfwDqIee4No X-Received: by 2002:a05:620a:278d:b0:77f:3265:b3ca with SMTP id g13-20020a05620a278d00b0077f3265b3camr27378482qkp.62.1703142508938; Wed, 20 Dec 2023 23:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703142508; cv=none; d=google.com; s=arc-20160816; b=JT2bs+FXJ8rp3QSPOEQR5K1SDX+FqQTDp/R7qOhJD3kiurcBnjU2onEvG6vZjYnD2X DTbsHKb9FtEZig8O6FRKb6RajDUqgr9Dm+E2oL+2LqjbDQ9ZstiUU79a95bgjCgTQ0hn /IKOMg30qhXxt/WErGYdrNOtatwqGHv27rpCXBIHQmjZ/cV68tNu5P/AKs/UR4G7xQGx rY5Rm4RgvzWIWxPd9sk0zR75fJnbJnaHN8NPKp4Zau7SPPu5gxke1E7vOwmbpDn3unU3 lofFm/7lTtiayd2+X+XiVR9LbGeFP6WYmXxMOilx94Ul5x+PwbZgkkHmLelsw3P13EjI 148Q== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7917-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bn5-20020a05620a2ac500b007810add037csi1577478qkb.494.2023.12.20.23.08.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 23:08:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7917-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; spf=pass (google.com: domain of linux-kernel+bounces-7917-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7917-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AFFFB1C22EA8 for ; Thu, 21 Dec 2023 07:08:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10532D26D; Thu, 21 Dec 2023 07:08:20 +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 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz4a-0 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)); } -- 2.20.1