From patchwork Mon May 1 21:05:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Drew Fustini X-Patchwork-Id: 13228343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A57FC77B73 for ; Mon, 1 May 2023 21:03:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i6mgN4eKKv3XfVvhAU6Cj9+86iagVF41Pvwkm3gj9Ww=; b=lnyevCOSDvp7tT iNJq2fve74P/oufuj3mL35Do/LoswCImt6LdSWJ8HTlnACPvYRLTFQI/uZp2VwchD4lai5A6SIUAQ KSZiFlA2WhLQD1vsDQfz2m/XOMNA52xVNVVQX4L1uWZoTfl56QHpq17vigd6qCAYDuRqDrdJ7yMgD ovSeZno0yACsFbuIUcbPfUq+ta/BCzEPdJaMYGqMt4NB9JnyjZ1WYUYRHrmelSrCgTFR0pLPuId9D 454pP4YwxcygEhu48GOAp8i32cKsDBftdZbHhPpD/wNIAZ+H2EKzrwnPOp9b023RLERw6Nw4kjAkR E9ruPbxYRnSivgIHTNwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ptafe-00Gy9I-0u; Mon, 01 May 2023 21:02:54 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ptafZ-00Gy75-2M for linux-riscv@lists.infradead.org; Mon, 01 May 2023 21:02:53 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-63b7096e2e4so2338641b3a.2 for ; Mon, 01 May 2023 14:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1682974967; x=1685566967; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=fctEC41u76rTML4CTTx2jHE+S5zx89fZLmwJsiIL5So=; b=gg6yVxNsBS5x4HtlfKW+Oxy+TgP/Op/y9K/EVFxOQfNO52SSvoDUOn8N6xzYKeEfko vGLAVc8SOZP5ecmjgvNQ73oT3hEfuH4gdCcoq3iP1jAzcYe3Csi1mVG9F+8uXLKs8RSt +6+51X+rhf4ZAeVr5XOxmEtsG+7SZZz9Zgw70ccJubeB1Z62q2Nb+jbrZkOzzik+HSb2 DmWrnvOhIvsWqFWRWr8e0aXOqF7alJb1XW2wS5CQDUbX4hMcUCkgfmrX5ghL2eP97NK/ u7h42xhr5BUHkwH68wK9RFNhvluEjf5jdIJb7vFyec5n1J7vn/KVdjIjzNryxfjRXwIx X7AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682974967; x=1685566967; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fctEC41u76rTML4CTTx2jHE+S5zx89fZLmwJsiIL5So=; b=a1J4uqaWMDUoKqLmQ8XDZ6dc05nsQ93sYXL576asSwR2PRvH5d6henneT1JTWdXndW XCY4rU0bnjDTXb0PRBadlcTufndtwblZB+WxL8u9Gyi4vzMoPdfDD1tdOwMHKuq5kSPW muYIh49zcUtCSmng/Yny1emwb8axZMkAsttbIxECKeeabw8d/B6Dq5GPsSlVuVh2QY5g O8LCZeybBii1vTH0y1hlZw67kcV4hq9T+ybFstESmRb8e+yQFQ3ZiKpuCiyLwMSE4tB2 X7NsC2W/1LKcEV/Knizx8MhdN0lKC9cG7eT4ZV1M76hNO7MTL0qfJonxl1sVlYDIunL/ TZtg== X-Gm-Message-State: AC+VfDxH7eAI0EjgpOWXxAYWPz1zrco5vAbTkRb+jhyRwUD6ppBcP3HD GoFqiAjyTyplQoDDgFwfJWsm4g== X-Google-Smtp-Source: ACHHUZ4Ou1HmHNgzOMSKxKB0s/OG17wi9Y6JHqnnmaYaJhcqoFkGF9PKAJGiOBUpRXnSdrb0GO4XXg== X-Received: by 2002:a05:6a00:1515:b0:63d:2aac:7b88 with SMTP id q21-20020a056a00151500b0063d2aac7b88mr23713638pfu.25.1682974967051; Mon, 01 May 2023 14:02:47 -0700 (PDT) Received: from [127.0.1.1] ([2601:1c2:1800:f680:1f1:1360:eb9b:387]) by smtp.gmail.com with ESMTPSA id i12-20020a056a00224c00b0063d670ad850sm20899151pfu.92.2023.05.01.14.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 14:02:46 -0700 (PDT) From: Drew Fustini Date: Mon, 01 May 2023 14:05:21 -0700 Subject: [PATCH RFC v2 1/2] RISC-V: Detect the Ssqosid extension MIME-Version: 1.0 Message-Id: <20230430-riscv-cbqri-rfc-v2-v2-1-8e3725c4a473@baylibre.com> References: <20230430-riscv-cbqri-rfc-v2-v2-0-8e3725c4a473@baylibre.com> In-Reply-To: <20230430-riscv-cbqri-rfc-v2-v2-0-8e3725c4a473@baylibre.com> To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Conor Dooley , Ved Shanbhogue , Atish Patra , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , James Morse , =?utf-8?q?Kornel_Dul=C4=99ba?= , Adrien Ricciardi , Drew Fustini X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1682975186; l=2210; i=dfustini@baylibre.com; s=20230430; h=from:subject:message-id; bh=HJmdwjdD3oLAOaRVmOzd9g/qKji+rF7c3nA/VaibzyY=; b=ABdeu5blg0kipm7ff+tcUDspwu9/Irg+HwQba+62HXEonmYZL76N4bgM+Fsa4Ab/8OoFAS9k2 HPZVbMh27zGA7a1Hz2eau+u3sSuY3Bohb2Wx6PMWXeBvQksg/b7W95y X-Developer-Key: i=dfustini@baylibre.com; a=ed25519; pk=p3GKE9XFmjhwAayAHG4U108yag7V8xQVd4zJLdW0g7g= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230501_140249_772174_C81D11AE X-CRM114-Status: UNSURE ( 9.42 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Kornel Dulęba Detect the Ssqosid extension (Supervisor-mode Quality of Service ID) as defined in the CBQRI (Capacity and Bandwidth QoS Register Interface) specification. Link: https://github.com/riscv-non-isa/riscv-cbqri/blob/main/riscv-cbqri.pdf Signed-off-by: Kornel Dulęba [dfustini: rebase from v6.0 to v6.3] Signed-off-by: Drew Fustini --- arch/riscv/include/asm/hwcap.h | 2 ++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 1 + 3 files changed, 4 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 9af793970855..6dd717030723 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -44,6 +44,8 @@ #define RISCV_ISA_EXT_ZIHINTPAUSE 32 #define RISCV_ISA_EXT_SVNAPOT 33 #define RISCV_ISA_EXT_ZICBOZ 34 +#define RISCV_ISA_EXT_SSQOSID 35 + #define RISCV_ISA_EXT_MAX 64 #define RISCV_ISA_EXT_NAME_LEN_MAX 32 diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index 3df38052dcbd..29c4d458377a 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -186,6 +186,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = { __RISCV_ISA_EXT_DATA(zihintpause, RISCV_ISA_EXT_ZIHINTPAUSE), __RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), + __RISCV_ISA_EXT_DATA(ssqosid, RISCV_ISA_EXT_SSQOSID), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL), __RISCV_ISA_EXT_DATA(svnapot, RISCV_ISA_EXT_SVNAPOT), diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 52585e088873..c824698b2031 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -229,6 +229,7 @@ void __init riscv_fill_hwcap(void) } else { /* sorted alphabetically */ SET_ISA_EXT_MAP("sscofpmf", RISCV_ISA_EXT_SSCOFPMF); + SET_ISA_EXT_MAP("ssqosid", RISCV_ISA_EXT_SSQOSID); SET_ISA_EXT_MAP("sstc", RISCV_ISA_EXT_SSTC); SET_ISA_EXT_MAP("svinval", RISCV_ISA_EXT_SVINVAL); SET_ISA_EXT_MAP("svnapot", RISCV_ISA_EXT_SVNAPOT); From patchwork Mon May 1 21:05:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Drew Fustini X-Patchwork-Id: 13228345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 28217C7EE26 for ; Mon, 1 May 2023 21:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:In-Reply-To:References:Message-Id: MIME-Version:Subject:Date:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gyemVJbcQ26y8diMsir/qncWanfSIpyeW3dlBbnHAZM=; b=BmiRoWMeaKd8GH Y4Wwbm1voMHqT//0xh8NW532OJqznr1XCVQQYLrq/dHSHKQdoC2kM13+rY/OeChTZs2qtMVgBHyJ+ zoT8luKSn80RouoSsSPwutTzQEPLnOWVZRkVItnhAtm2bPD4UfhdjZgakl3bM2hHNEzaxgE66wm55 3gSl8ADDoPJT7AvBo1B6NPuuUePJB9Q2IyCTLcPgAhV96VbVNT4h2412/nUVzAQzAeLUVIx+xUiUB 803/GitGC3uw0SDuGObeJ8ZIilQHZzGQCPofTGKQU1/SQSA9wi7JT27CawnhvDdxvtfY4gOpnfI25 yGidfYqjWIoHSBAcbsYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ptafe-00Gy9u-2e; Mon, 01 May 2023 21:02:54 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ptafa-00Gy7F-0e for linux-riscv@lists.infradead.org; Mon, 01 May 2023 21:02:53 +0000 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-51b603bb360so2526228a12.2 for ; Mon, 01 May 2023 14:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20221208.gappssmtp.com; s=20221208; t=1682974968; x=1685566968; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=D0PMc06A2yO1+4gBCh6kqZ9mPyJIp2PmIrRbClN4AUU=; b=22pB7WZDuACv8vKwyma11RORQBTgeLJOhEWaVOHjR4k1EQ0m1ccauLXSPMoS3CqUI/ Rmt/TNm93ODh6yu4l+tzgcaPwUwVghZn9Jisri9HzX0plEHuvrRu2qxW74AqeNGf8eKk KZNN+IdcPduuRJJuPHMyQ/Wo+y9GBQDMtyKx+rbVQOUHJRC1/Uk6EyD+AEMMZiWBBFnk yJ+xL0NBALIifCIO9X7ncLxEpoHDsgAV0JzhuJA5vhpB5p82OR90CGnJ8h6RKMyFj7xL V60Q1Juh68HPQPuHaYSQB/KenVA7usLPla0Gp4iTzeBZdo4WCwuYayOSbP8MqNZEjDMV iD7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682974968; x=1685566968; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D0PMc06A2yO1+4gBCh6kqZ9mPyJIp2PmIrRbClN4AUU=; b=Yu9wkdNqpOzHPf/DsUc9b+cNnUNbd8hh8IXsRUYGvCZ5wmWPNESgDeptXqWmO94TMm aLyShjnKoZAhFoT6nqlFq+w7B0jAAcbk5aeUqkR6mcr2j+pt7VTR1bqA4ZzoW9WiHu5Y Z7iQIT0pwbD3ZXrhtUfwPbanRd1yjmBVOKNqdeJqUCl3CbeH0DAa06uLcV6he6gZpd9j BEEBHNqouhzm0x7i05KNt02g/6jQ+B8huDG0qNZkET3cvneQAmFjCd5NhnHuALAm5rYc QH8HeFianxuqG2IGizGWK0DXiDsGCQfdvIBXEl6jV4h+Fy7f3q+MslJIfSmA2e8/MJDO RnlA== X-Gm-Message-State: AC+VfDxPNmk8IPQYKEKlIAeoO5+Aed+pXyDcv3wdBd8scJgsmhgrIU3a TrcEjrCW/6/an2YgZrNZiWX8Hg== X-Google-Smtp-Source: ACHHUZ7JntkrxpTw7Ce1AQ2PUesqX2qhhXG3Smz+hSrCFgp2HGEQOm3YMYdv9ENcPs4dJ+3sdr21MA== X-Received: by 2002:a05:6a20:3c8b:b0:f2:93b7:a452 with SMTP id b11-20020a056a203c8b00b000f293b7a452mr18876852pzj.4.1682974968123; Mon, 01 May 2023 14:02:48 -0700 (PDT) Received: from [127.0.1.1] ([2601:1c2:1800:f680:1f1:1360:eb9b:387]) by smtp.gmail.com with ESMTPSA id i12-20020a056a00224c00b0063d670ad850sm20899151pfu.92.2023.05.01.14.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 14:02:47 -0700 (PDT) From: Drew Fustini Date: Mon, 01 May 2023 14:05:22 -0700 Subject: [PATCH RFC v2 2/2] RISC-V: Add support for sqoscfg CSR MIME-Version: 1.0 Message-Id: <20230430-riscv-cbqri-rfc-v2-v2-2-8e3725c4a473@baylibre.com> References: <20230430-riscv-cbqri-rfc-v2-v2-0-8e3725c4a473@baylibre.com> In-Reply-To: <20230430-riscv-cbqri-rfc-v2-v2-0-8e3725c4a473@baylibre.com> To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Conor Dooley , Ved Shanbhogue , Atish Patra , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , James Morse , =?utf-8?q?Kornel_Dul=C4=99ba?= , Adrien Ricciardi , Drew Fustini X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1682975186; l=7192; i=dfustini@baylibre.com; s=20230430; h=from:subject:message-id; bh=pWQVrZDB0/WwGsPOU+vgZxpwWoA9+OJKEaCTiIWYn6w=; b=VjMXT5Dzf04LphERS+3SbW74JjkhLQUHjOPgLeAFISnPcRs305me/gjpnAkZckj+fzNbuxsdN vRjJTMbr2LrCpv4aWJlJNcPV4OIZOMfcc9gZEKjrBn+TM89MWzdC+3C X-Developer-Key: i=dfustini@baylibre.com; a=ed25519; pk=p3GKE9XFmjhwAayAHG4U108yag7V8xQVd4zJLdW0g7g= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230501_140250_236871_AE407D81 X-CRM114-Status: GOOD ( 23.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add support for the sqoscfg CSR defined in the Ssqosid ISA extension (Supervisor-mode Quality of Service ID). The CSR contains two fields: - Resource Control ID (RCID) used determine resource allocation - Monitoring Counter ID (MCID) used to track resource usage Requests from a hart to shared resources like cache will be tagged with these IDs. This allows the usage of shared resources to be associated with the task currently running on the hart. A sqoscfg field is added to thread_struct and has the same format as the sqoscfg CSR. This allows the scheduler to set the hart's sqoscfg CSR to contain the RCID and MCID for the task that is being scheduled in. The sqoscfg CSR is only written to if the thread_struct.sqoscfg is different from the current value of the CSR. A per-cpu variable cpu_sqoscfg is used to mirror that state of the CSR. This is because access to L1D hot memory should be several times faster than a CSR read. Also, in the case of virtualization, accesses to this CSR are trapped in the hypervisor. Link: https://github.com/riscv-non-isa/riscv-cbqri/blob/main/riscv-cbqri.pdf Co-developed-by: Kornel Dulęba Signed-off-by: Kornel Dulęba Signed-off-by: Drew Fustini --- arch/riscv/Kconfig | 19 +++++++++++++++++ arch/riscv/include/asm/csr.h | 8 +++++++ arch/riscv/include/asm/processor.h | 3 +++ arch/riscv/include/asm/qos.h | 43 ++++++++++++++++++++++++++++++++++++++ arch/riscv/include/asm/switch_to.h | 3 +++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/qos/Makefile | 2 ++ arch/riscv/kernel/qos/qos.c | 5 +++++ 8 files changed, 84 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c58d74235363..4de2ce69f9fa 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -409,6 +409,25 @@ config RISCV_ISA_C If you don't know what to do here, say Y. +config RISCV_ISA_SSQOSID + bool "Ssqosid extension support for supervisor mode QoS ID" + default y + help + Adds support for the Ssqosid ISA extension (Supervisor-mode + Quality of Service ID). + + Ssqosid defines the sqoscfg CSR which allows the system to tag + the running process with RCID (Resource Control ID) and MCID + (Monitoring Counter ID). The RCID is used determine resource + allocation. The MCID is used to track resource usage in event + counters. + + For example, a cache controller may use the RCID to apply a + cache partitioning scheme and use the MCID to track how much + cache a process, or a group of processes, is using. + + If you don't know what to do here, say Y. + config RISCV_ISA_SVNAPOT bool "Svnapot extension support for supervisor mode NAPOT pages" depends on 64BIT && MMU diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 7c2b8cdb7b77..17d04a0cacd6 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -59,6 +59,13 @@ #define SATP_ASID_MASK _AC(0xFFFF, UL) #endif +/* SQOSCFG fields */ +#define SQOSCFG_RCID_MASK _AC(0x00000FFF, UL) +#define SQOSCFG_MCID_MASK SQOSCFG_RCID_MASK +#define SQOSCFG_MCID_SHIFT 16 +#define SQOSCFG_MASK ((SQOSCFG_MCID_MASK << SQOSCFG_MCID_SHIFT) | \ + SQOSCFG_RCID_MASK) + /* Exception cause high bit - is an interrupt if set */ #define CAUSE_IRQ_FLAG (_AC(1, UL) << (__riscv_xlen - 1)) @@ -245,6 +252,7 @@ #define CSR_STVAL 0x143 #define CSR_SIP 0x144 #define CSR_SATP 0x180 +#define CSR_SQOSCFG 0x181 #define CSR_STIMECMP 0x14D #define CSR_STIMECMPH 0x15D diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index 94a0590c6971..724b2aa2732d 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -39,6 +39,9 @@ struct thread_struct { unsigned long s[12]; /* s[0]: frame pointer */ struct __riscv_d_ext_state fstate; unsigned long bad_cause; +#ifdef CONFIG_RISCV_ISA_SSQOSID + u32 sqoscfg; +#endif }; /* Whitelist the fstate from the task_struct for hardened usercopy */ diff --git a/arch/riscv/include/asm/qos.h b/arch/riscv/include/asm/qos.h new file mode 100644 index 000000000000..9d0fe1ac1b34 --- /dev/null +++ b/arch/riscv/include/asm/qos.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_QOS_H +#define _ASM_RISCV_QOS_H + +#ifdef CONFIG_RISCV_ISA_SSQOSID + +#include +#include + +#include +#include +#include + +/* cached value of sqoscfg csr for each cpu */ +DECLARE_PER_CPU(u32, cpu_sqoscfg); + +static inline void __switch_to_sqoscfg(struct task_struct *prev, + struct task_struct *next) +{ + u32 *cpu_sqoscfg_ptr = this_cpu_ptr(&cpu_sqoscfg); + u32 thread_sqoscfg; + + thread_sqoscfg = READ_ONCE(next->thread.sqoscfg); + + if (thread_sqoscfg != *cpu_sqoscfg_ptr) { + *cpu_sqoscfg_ptr = thread_sqoscfg; + csr_write(CSR_SQOSCFG, thread_sqoscfg); + } +} + +static __always_inline bool has_sqoscfg(void) +{ + return riscv_has_extension_likely(RISCV_ISA_EXT_SSQOSID); +} + +#else /* ! CONFIG_RISCV_ISA_SSQOSID */ + +static __always_inline bool has_sqoscfg(void) { return false; } +#define __switch_to_sqoscfg(__prev, __next) do { } while (0) + +#endif /* CONFIG_RISCV_ISA_SSQOSID */ + +#endif /* _ASM_RISCV_QOS_H */ diff --git a/arch/riscv/include/asm/switch_to.h b/arch/riscv/include/asm/switch_to.h index 60f8ca01d36e..79e8e907d7a6 100644 --- a/arch/riscv/include/asm/switch_to.h +++ b/arch/riscv/include/asm/switch_to.h @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_FPU extern void __fstate_save(struct task_struct *save_to); @@ -78,6 +79,8 @@ do { \ struct task_struct *__next = (next); \ if (has_fpu()) \ __switch_to_aux(__prev, __next); \ + if (has_sqoscfg()) \ + __switch_to_sqoscfg(__prev, __next); \ ((last) = __switch_to(__prev, __next)); \ } while (0) diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 0fee73a20c87..22c18b916212 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -89,3 +89,4 @@ obj-$(CONFIG_COMPAT) += compat_signal.o obj-$(CONFIG_COMPAT) += compat_vdso/ obj-$(CONFIG_64BIT) += pi/ +obj-$(CONFIG_RISCV_ISA_SSQOSID) += qos/ diff --git a/arch/riscv/kernel/qos/Makefile b/arch/riscv/kernel/qos/Makefile new file mode 100644 index 000000000000..9f996263a86d --- /dev/null +++ b/arch/riscv/kernel/qos/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_RISCV_ISA_SSQOSID) += qos.o diff --git a/arch/riscv/kernel/qos/qos.c b/arch/riscv/kernel/qos/qos.c new file mode 100644 index 000000000000..a6956664dfe1 --- /dev/null +++ b/arch/riscv/kernel/qos/qos.c @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include + +/* cached value of sqoscfg csr for each cpu */ +DEFINE_PER_CPU(u32, cpu_sqoscfg);