From patchwork Fri Nov 24 07:21:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 13467079 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 07B35C61DF4 for ; Fri, 24 Nov 2023 07:22:38 +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:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ZzHQGule67OmzxR16o7PvKNKU7mWXIfUDE/5q2t//IU=; b=d0Hc0d2dE2JfBr gVUBFzgH7MBXqpI32tfcC5DdQCnWP3iCPoN5yDeHnSDYZPfoggPusrAwGWEAYquqeq7/H+7TfB4K0 KC73Lg13rjFp768a5+wP+11y7aVxS90a0NsR79qFR+Bx0PkW2dbI71xzZBEo6sZkfAKO0sV+apzw3 dXK0iquoemYsuB30/whXi979pshZjZHTBrLbmWojTwJnXj/l9F40bc4R+pLAeUsLdfQroAl3eqdfe iTfgivjnUO33HvZxKe0EX1s2hARq9WfxqPzCxWSGGmKV8vCqbgB2puzj+lNExQfdLI3k9yXuCSm0D ee2AhJGVGepy1BdKTbHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r6QWH-006NYl-0f; Fri, 24 Nov 2023 07:22:33 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r6QWD-006NUt-1L for linux-riscv@lists.infradead.org; Fri, 24 Nov 2023 07:22:31 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50aa8c0af41so2734701e87.1 for ; Thu, 23 Nov 2023 23:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1700810545; x=1701415345; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=A+QJwQ2ibzfm4ZH4G7RxTWHsFFrHVq+i8PDqnY0Hrac=; b=mh6Q+YxVW3uVRpszAJzOhW5eot0dJRT8h182UWg5S8VdVAHDgChw9xajeQ4clg8vBi h8/qOAHmcT/YmzDUWMHcE+a2ZqXa91ABofqmSKPeyMBRkOd+61nJ/jsB/0D+AFEPna9x v2h6tDRIXUV3XD06NYcUf+csgqNa2xEmpDSTyn0KVimR5tAEyipIxT5iUUtGY13WKYZx KoCllTsLtjB3hv5b+bql9CxPcxaTAdbBynqIOULmsLFfTkitZy7IUoYilGVC6GQfx2dR UjlVdKwqLeL8W7LRGubeb93JuFZQGI+Oz5ZvFL0gbbXeWlMibzeZ6KCjYXEggjfBpAz3 YWeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700810545; x=1701415345; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A+QJwQ2ibzfm4ZH4G7RxTWHsFFrHVq+i8PDqnY0Hrac=; b=Tf9PtTqIYSpBzlMqH44jlSrc+GLYHR+Cg11CA0yb/ce5dC47AWMKj0cka+tqGMhFfY ko0OxKOvctOXM8gqgvJrIGn5M6ImMFpL1SAsJMRPYKXi2z77erOYXQ1psX+lVtSQd4/3 nZ962/Vm7XrxD2NoC80YKQF8z067HnR9P7Yenh+rblak5CxMFEfdxyaGejB0xf4jd3tt SNpODDi4O7j47OySQNqvcS6i/K3vYh0n/VixdFVPLqrMOkddtas0NHjAr0uwknM7fXEb K6Do7zBntKOOPh3a0KnTQmrWN0qvJfWAecDKBsLpVctYT2SRZ6QQw6cDEsWvKinvbuzo yJ6Q== X-Gm-Message-State: AOJu0YzTlehuvomVRFh373sHzSZWyJufh0jFTKdTUYs6qiO8fbDJzlQ5 Hg2DN+nTESmcIcbmwQ7JTirX4UaTVN8WlotBqMtRijGm X-Google-Smtp-Source: AGHT+IG4KyTl5CwzMZ1gy4FucyPBBLxaEgYRfo01XZveBgxlerDUkvXhDFprA+AP7dQahAlFaE4+/g== X-Received: by 2002:a17:906:2259:b0:9ee:a767:12e7 with SMTP id 25-20020a170906225900b009eea76712e7mr1762679ejr.6.1700810524590; Thu, 23 Nov 2023 23:22:04 -0800 (PST) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id q18-20020a1709060e5200b00992f2befcbcsm1709930eji.180.2023.11.23.23.22.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 23:22:04 -0800 (PST) From: Christoph Muellner To: linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Albert Ou , Andrew Morton , Shuah Khan , Jonathan Corbet , Anup Patel , Philipp Tomsich , Andrew Jones , Guo Ren , Daniel Henrique Barboza , Conor Dooley , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Alan Stern , Andrea Parri , Will Deacon , Daniel Lustig , Peter Zijlstra Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH 0/5] RISC-V: Add dynamic TSO support Date: Fri, 24 Nov 2023 08:21:37 +0100 Message-ID: <20231124072142.2786653-1-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231123_232229_458252_C0D33694 X-CRM114-Status: GOOD ( 16.86 ) 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: Christoph Müllner The upcoming RISC-V Ssdtso specification introduces a bit in the senvcfg CSR to switch the memory consistency model at run-time from RVWMO to TSO (and back). The active consistency model can therefore be switched on a per-hart base and managed by the kernel on a per-process/thread base. This patch implements basic Ssdtso support and adds a prctl API on top so that user-space processes can switch to a stronger memory consistency model (than the kernel was written for) at run-time. I am not sure if other architectures support switching the memory consistency model at run-time, but designing the prctl API in an arch-independent way allows reusing it in the future. The patchset also comes with a short documentation of the prctl API. This series is based on the second draft of the Ssdtso specification which was published recently on an RVI list: https://lists.riscv.org/g/tech-arch-review/message/183 Note, that the Ssdtso specification is in development state (i.e., not frozen or even ratified) which is also the reason why I marked the series as RFC. One aspect that is not covered in this patchset is virtualization. It is planned to add virtualization support in a later version. Hints/suggestions on how to implement this part are very much appreciated. Christoph Müllner (5): RISC-V: Add basic Ssdtso support RISC-V: Expose Ssdtso via hwprobe API uapi: prctl: Add new prctl call to set/get the memory consistency model RISC-V: Implement prctl call to set/get the memory consistency model RISC-V: selftests: Add DTSO tests Documentation/arch/riscv/hwprobe.rst | 3 + .../mm/dynamic-memory-consistency-model.rst | 76 ++++++++++++++++++ arch/riscv/Kconfig | 10 +++ arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/dtso.h | 74 ++++++++++++++++++ arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/processor.h | 8 ++ arch/riscv/include/asm/switch_to.h | 3 + arch/riscv/include/uapi/asm/hwprobe.h | 1 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpufeature.c | 1 + arch/riscv/kernel/dtso.c | 33 ++++++++ arch/riscv/kernel/process.c | 4 + arch/riscv/kernel/sys_riscv.c | 1 + include/uapi/linux/prctl.h | 5 ++ kernel/sys.c | 12 +++ tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/dtso/.gitignore | 1 + tools/testing/selftests/riscv/dtso/Makefile | 11 +++ tools/testing/selftests/riscv/dtso/dtso.c | 77 +++++++++++++++++++ 20 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 Documentation/mm/dynamic-memory-consistency-model.rst create mode 100644 arch/riscv/include/asm/dtso.h create mode 100644 arch/riscv/kernel/dtso.c create mode 100644 tools/testing/selftests/riscv/dtso/.gitignore create mode 100644 tools/testing/selftests/riscv/dtso/Makefile create mode 100644 tools/testing/selftests/riscv/dtso/dtso.c