From patchwork Wed Nov 22 03:05:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 168072 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp1066459vqb; Tue, 21 Nov 2023 19:07:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEG/GOQ/iqqHcvxeFYdRNKmUsmHxnGL0Ew9LvXzl63LODjZwoDBpn0sxvtSWBzz3OqJrHnh X-Received: by 2002:a05:6a00:181d:b0:68f:b5cb:ced0 with SMTP id y29-20020a056a00181d00b0068fb5cbced0mr1255440pfa.34.1700622475793; Tue, 21 Nov 2023 19:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700622475; cv=none; d=google.com; s=arc-20160816; b=QWPptOnn08Oc8wplQcQIgr6aRjztSKUzeF8pNyYFfD3MBLAnEXt3pOGx9hAsBShQid QR6NHJo3wCjjZfcOo+oG5aPss4GrlK8TVFqCTWIElQqWOICtmqt2oThLFiXgqbl9UfoT ZvsuSFevFbqXnD5w3H+v3tE1Q4ow9wJagD9e6Jp3uhzJNtAE6sVaQIQ2Jo+drLSMjGPf Q6KC+a6VH89vCwr0MwbOcBwEV+QpvVcb2QDO5Nr5Jb34OcDrSft8CkJkRkR43h5DHrJm f6nujk7lVsbLSd/ezigLJ3Eyat41igx2pCRKgERUyoeiUxRheScOTMnAdIq42CpeJRvf kA/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xQTyfvTA/sT9rfHfHNgSFRFvzietrqmBvaroSzp1CzI=; fh=xt7kleNiHeDzzXD5a4JNSIZKK9T1WXEfVTIepMmIT7Q=; b=LTaDFimmG2O8kGXDnY2RtN+Fy2ha/shUAkNPjJdynckhgjkGWbxkTgDMrpNDYdaJSe lUV8g/OlZzGdxNssOsG0CeZmNGK6oGrAXEBRVEGpWLmFE1o0HGDShLvGR5aE2kYUyOy+ OJmkxhjgVfqnzoRBgNULCXwuo7geU8m8yKJ7YEI9RI8aVOrSEcyQNb+AZnyfjyeWsV1v xt6qLaxP+8d4RJwpBFTs+6bmG3726K90p0KOgvnmYHN8obPLfO27Fpt7rm+NiXQ0cM4A 9qTka/HF7w4hkTBkIEDo2/DXWiMoQP9PoCovG4WaryiujJ7t+uZbn8Cf7MgFHofaUAox cIdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=GJkkVI7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s26-20020a056a00179a00b006cb88a16f29si6358923pfg.161.2023.11.21.19.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 19:07:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=GJkkVI7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DA71280BE2DE; Tue, 21 Nov 2023 19:06:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343530AbjKVDGd (ORCPT + 99 others); Tue, 21 Nov 2023 22:06:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235035AbjKVDGb (ORCPT ); Tue, 21 Nov 2023 22:06:31 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF6E012C for ; Tue, 21 Nov 2023 19:06:27 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6c115026985so6373921b3a.1 for ; Tue, 21 Nov 2023 19:06:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1700622387; x=1701227187; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xQTyfvTA/sT9rfHfHNgSFRFvzietrqmBvaroSzp1CzI=; b=GJkkVI7WcCmlpXCnMuay2CNDJOZacbcwlgUAnb8Xfl4Xaz2iatpSI1l7x9cpE4ESN/ uyVSUTJC/LEsx1/KfZedaEpHA1mntL7uq7t0lMu9yA6nxIRXz4Ek26Z5JyBCvsphNz0H QCuHig0kc/J4QI8BMl0O6qfr1jJSFa7cLoZLHMn4Z2JeX+ey0RA07pqUYU896/pMZ9Y9 /ar2HKRhvcjrYuYxrVkZmO9RhDsvZQgDrn8QA7+shJ3uG9sbtqEmuldlybyJYIGdM0x4 3ZgNOBIdtOfvwZbSxso0IUV+iego45YucPVUIw+7tm+zLgchCuOsteANbg1FtHarMosh 42pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700622387; x=1701227187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xQTyfvTA/sT9rfHfHNgSFRFvzietrqmBvaroSzp1CzI=; b=uF5/Lp3w5AdeWCQh8Bq6/ihT8WyrfVVY+Fkdjs+Df5ppASnhzCMoveOadSL8ImXWWW 556GV+oE+eF5Y+X3yi1mGaIUSgR93petnIdWLM8omUSGmra3/JugBpyXf15tepmku9gw 5FyXTk9AA6g9lxZx6Fgqz0EvX9bHUn9O7iLF5bkeJPpFgwWfptVBDeA+Duaa8B8ZKc6l uZ3WvNuTQ5sOcFSSaXC8sZFTyLmPPsXwt+FEnBw8SRAz9BjN9YPretBOkCS4H5af8PP6 U+QUURxf/bc720D2Ka4DZ4yeYvmpIk4Vko7n0plwnmo/4bqCyW8W9Nz4Y7EPOkFvLJcX B3wA== X-Gm-Message-State: AOJu0YyiZszv/MgVzBb+i8dY0NLIxmyvqHGYf3eEOGcRZgdhcDHiyKYp ZJAGR+p8G47ntGmEd+OUeOwC4A== X-Received: by 2002:a05:6a20:78a2:b0:186:2389:a73e with SMTP id d34-20020a056a2078a200b001862389a73emr933242pzg.55.1700622387226; Tue, 21 Nov 2023 19:06:27 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id s2-20020aa78282000000b006a77343b0ccsm8614917pfm.89.2023.11.21.19.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 19:06:26 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , Harry Wentland , Leo Li , Rodrigo Siqueira , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, David Airlie , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , Pan Xinhui , Daniel Vetter , amd-gfx@lists.freedesktop.org, Samuel Holland Subject: [PATCH 1/3] riscv: Add support for kernel-mode FPU Date: Tue, 21 Nov 2023 19:05:13 -0800 Message-ID: <20231122030621.3759313-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231122030621.3759313-1-samuel.holland@sifive.com> References: <20231122030621.3759313-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 21 Nov 2023 19:06:35 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783231913049139648 X-GMAIL-MSGID: 1783231913049139648 This is needed to support recent hardware in the amdgpu DRM driver. The FPU code in that driver is not performance-critical, so only provide the minimal support. Signed-off-by: Samuel Holland --- arch/riscv/include/asm/switch_to.h | 14 ++++++++++++++ arch/riscv/kernel/process.c | 3 +++ 2 files changed, 17 insertions(+) diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index f90d8e42f3c7..4b15f1292fc4 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -63,6 +63,20 @@ static __always_inline bool has_fpu(void) return riscv_has_extension_likely(RISCV_ISA_EXT_f) || riscv_has_extension_likely(RISCV_ISA_EXT_d); } + +static inline void kernel_fpu_begin(void) +{ + preempt_disable(); + fstate_save(current, task_pt_regs(current)); + csr_set(CSR_SSTATUS, SR_FS); +} + +static inline void kernel_fpu_end(void) +{ + csr_clear(CSR_SSTATUS, SR_FS); + fstate_restore(current, task_pt_regs(current)); + preempt_enable(); +} #else static __always_inline bool has_fpu(void) { return false; } #define fstate_save(task, regs) do { } while (0) diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index 4f21d970a129..6a18bc709d1c 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -225,3 +225,6 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) p->thread.sp = (unsigned long)childregs; /* kernel sp */ return 0; } + +EXPORT_SYMBOL_GPL(__fstate_save); +EXPORT_SYMBOL_GPL(__fstate_restore);