From patchwork Mon Nov 27 14:56:02 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: 80826 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99D05386075C for ; Mon, 27 Nov 2023 14:56:27 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 6A35738582B9 for ; Mon, 27 Nov 2023 14:56:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A35738582B9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A35738582B9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701096973; cv=none; b=bZ6JghQ3BZNM47400Bw4ZhIZzjamKePGc9AImaPOe4whi3wrOcqeTQaf7YmIYx/hpqjIbyAvdkhuuULIsgHL/V11x/WSvwRhUkXI4RqNPolrQjO8JfK+Rt3vlgPv5VtZsAXxaO8tTuOGZBEK/LD4h3HdJkLTjcLbOJN16XbD5OU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701096973; c=relaxed/simple; bh=ri4VXIdA2Bmp5e5z7/vGG2rgXG6FAeEQiKxsgS68wA0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JQZjwlAJZ82nAvX75dYk5EmOw2NIvXo0K47p7RzrOhSaTCE55yHgGSzN0oY85cYVkIkdA4JGOQIT53W/Td/8z2H835Ejw4aRDbjJGznWMJVds+LT9ABaglvIJ+N/0qPLGKgnWZ2OsnebKGgZn8mJgjwGZPJhgSQlf+4XhMhMdQo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c876e44157so53171071fa.2 for ; Mon, 27 Nov 2023 06:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1701096970; x=1701701770; darn=sourceware.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=EqhoT1n3t/3K2V277mEEFBGy3D9lkqOVwlaUcVuGWNM=; b=IEg8l1SlO2kVHjSApEv+sdCfo2iV7XRdfO124c681Vk1vEMx8+zt3wrMfPMoNnSb53 ODcJlPGbvxfFbAvFzcS7dukmF5UhZTk3+LaSFriXHpIsmIyFW/C0vPYelIuD+H1+N+rW jg+xEy5qg5fAba3I8V8FS+KjptLOsaYKb5eBYHCe4vmb3ndZpIyuYpQSAzxcfuhxpCzH Y5xFUc8Ahfvcf1WYaODf+/ZyEYXOigD9tT5/LqOqvBb0YguVsf8yOZBhM+VIOe2z47ov LlppiwI3QjCJ8p/JkS+tvb/ezwPfAo+KGBTVMsrzXk7tmjYvnJhFXqtJ42CzK1w07+p5 gUdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701096970; x=1701701770; 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=EqhoT1n3t/3K2V277mEEFBGy3D9lkqOVwlaUcVuGWNM=; b=btq0Sybh/LiQQalTt0fFZqoQZJtN/fhSD+vUKf565ikQWCiH0jnqwcBnPHPa6C1ODW 1Y8T6x6u22MJOuPWXuHxXbVkzk1p5AnDQ2Lq5by9Ei/ORxrhcDhNW72tvrC+nkFsxnND UdTToowmqN4o9Jj69Nj1CzutcDii6IdC5M7d43o7qk8LMMi2oWMdUUx8zK7CAHW1cTmE 67yfNfyihiq0GGtnWpstOEmfxy/FJ28XuVMAllItP+KMSD7ysIXUztxTTEJBRDwT5c8v Dfbm7bbpJc97eHtivQIGnrKRGWaW906OBbaVyzS3OnHyafQJ+nJ6ILbsNHDpcdE69yWK jyhA== X-Gm-Message-State: AOJu0YxLglscXlV3qCatSH80FVkmYPz1/NRwj4xhJwEit/4zvVabXFD0 wWlIVCCkSfEuBPGCgzJ8EqaneGEQyJcYvYYuMw5mGw== X-Google-Smtp-Source: AGHT+IF67geGko/EvqC348V1G1+RMkzjI5d6j9LtXNQpqPFKL8XCSOlJR1+52tL4FxLTV+yyPuE4/g== X-Received: by 2002:a05:651c:c7:b0:2c8:83c4:9069 with SMTP id 7-20020a05651c00c700b002c883c49069mr8633768ljr.2.1701096970292; Mon, 27 Nov 2023 06:56:10 -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 a20-20020a1709063e9400b00a0369e232bfsm5753427ejj.75.2023.11.27.06.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:56:09 -0800 (PST) From: Christoph Muellner To: libc-alpha@sourceware.org, Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH 1/2] RISC-V: Move TSO check to elf_machine_matches_host() Date: Mon, 27 Nov 2023 15:56:02 +0100 Message-ID: <20231127145603.2339644-2-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231127145603.2339644-1-christoph.muellner@vrull.eu> References: <20231127145603.2339644-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org From: Christoph Müllner The current implementation does not support ELF files which have the EF_RISCV_TSO ELF flag set. This is implemented in process_elf64_file(), with the assumption that no TSO-capable hosts exists. In order to weaken this restriction, let's move the TSO flag check into elf_machine_matches_host(), where compatibility with the host can be checked. This patch serves as a preparation for further changes and does not intend to implement any functional changes. Signed-off-by: Christoph Müllner --- sysdeps/riscv/dl-machine.h | 4 ++++ sysdeps/unix/sysv/linux/riscv/readelflib.c | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index c0c9bd93ad..ce537731dd 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -72,6 +72,10 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) return 0; #endif + /* Execution of TSO binaries is not supported at this time. */ + if (ehdr->e_flags & EF_RISCV_TSO) + return 0; + return 1; } diff --git a/sysdeps/unix/sysv/linux/riscv/readelflib.c b/sysdeps/unix/sysv/linux/riscv/readelflib.c index 788eba8305..e2bd4d7727 100644 --- a/sysdeps/unix/sysv/linux/riscv/readelflib.c +++ b/sysdeps/unix/sysv/linux/riscv/readelflib.c @@ -30,10 +30,9 @@ int process_elf64_file (const char *file_name, const char *lib, extension, we can still support libraries compiled without that extension so we just ignore this flag. - EF_RISCV_RVE: glibc (and Linux) don't support RV32E based systems. - - EF_RISCV_TSO: The TSO extension isn't supported, as doing so would require - some mechanism to ensure that the TSO extension is enabled which doesn't + - EF_RISCV_TSO: Accepted with restrictions (see elf_machine_matches_host). currently exist. */ -#define SUPPORTED_ELF_FLAGS (EF_RISCV_FLOAT_ABI | EF_RISCV_RVC) +#define SUPPORTED_ELF_FLAGS (EF_RISCV_FLOAT_ABI | EF_RISCV_RVC | EF_RISCV_TSO) /* Returns 0 if everything is ok, != 0 in case of error. */ int From patchwork Mon Nov 27 14:56:03 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: 80827 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C6943861800 for ; Mon, 27 Nov 2023 14:56:32 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 09EE3385801A for ; Mon, 27 Nov 2023 14:56:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09EE3385801A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 09EE3385801A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701096974; cv=none; b=d9vT6hdPgJiIPYPmaX2/yesMD4wuEK4ian5J6LtPel42tjYFAxcWmaHsrpPLgo3BEza8LE0FAeIB7reDOC3//XKU4LN/QKfNN2irgibzx5NUkfieN3ygG9c10/UNNChlcZfbN3T5K5wgiVN+R75/BdfXdU/8OKBQRdjyPhbSZmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701096974; c=relaxed/simple; bh=Ke/ekC/87rxBW47wlMFpjBvDjgYSZ5YNALnvTwptKq4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=q55s3TEUsbRlmorru0WGDUrJ7NVjYttE+lk3RB84daPvgJgFQHzjRnvcJPKqtKL+FVspFcMSciqpa8hK3hgTbi6yCZ8ZqWyjVGLzeeDGXH7TtaHSjXlUhpRtrlSO1LkJ2YJtnIPjFAnfYD/jbR8IQ/yCI0OyKAzJYoa2iPPIw6c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a0064353af8so1035122266b.0 for ; Mon, 27 Nov 2023 06:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1701096971; x=1701701771; darn=sourceware.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=eLXckxQQnxg1bbhOe5KhVuhCpiG8JEnhweNtnUlAcSs=; b=AqchXEspHfjhGTE5B57F7lE49CUOrKJ/YNq8f0Trd1lGRZtRO/Fg9PoLfcEeLFxTIh ZmNmbeDABfIoGNZ+jqUpnrdDLo3z5o2/DhJwu+K8eTEXBECMjjvOrCpnFJRUMjDogPhi V8D6/YkTCZvoHTzxjYznxm4d/3Gu63RXD8OD+0A9+ZiyxxCyhrOrEe9iUW/RiHsaH7T4 V07ZZQs2zdztd+P28NS/aWJwMzXrqZ8IITSxwi3C8EcYQxiUs0AKUixCv5moK4jr+uaX ytT2lHp4kTrt/ExJvixs6OXpsnzajwCN0A3YNeV70RDNoJJnjitSHvucedH3pyYKVY9T wI8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701096971; x=1701701771; 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=eLXckxQQnxg1bbhOe5KhVuhCpiG8JEnhweNtnUlAcSs=; b=xKsJ5IysaqjTRh9kwyTERGX4h/qvpugDIInBa/9ienIE52s6HNQRinEYQ44ZDeyztn 2gJld+64Xf7nF2UdsbU+ErOKAAhWIcnMOYrurkoUqF4maOwCtoDXe2Srh/uQ+nXYX6gw C+qpWbp4LQ5VIaQSEN4uaETAryzoGvDgcbDVSmUy0YyEc3lRlPisfYSphJ7NY0uPu5VD 8GCoauv7gT2sEBmHiOTDMeyyC16iXWgEmkDjNx359OQ1ZFuIA9Crcvw0ygw2J/6goJbe GWq9+Zm/cayzVNjchPouNik26RRrHc0lf0w5NiyMJgqZPM+l6jh/DsvC9r0e+0MPr+hw e+EQ== X-Gm-Message-State: AOJu0YzCkPefntscS58y+no3AH0UvW7a8hT7AzZOmpJ/ts6j6jkpkWM5 tcON7CyP9Qqfes/U1iN44HXToYmthmsz5D+vZWxoUg== X-Google-Smtp-Source: AGHT+IFdW0pj4UcBKIasYVOHBI5i4CdDBpXKs4DtwWcdMqpTY9jthLAs5vCvaPwixU0x8VQjdieePQ== X-Received: by 2002:a17:906:2bd1:b0:9e8:2441:5cd4 with SMTP id n17-20020a1709062bd100b009e824415cd4mr8747646ejg.17.1701096971442; Mon, 27 Nov 2023 06:56:11 -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 a20-20020a1709063e9400b00a0369e232bfsm5753427ejj.75.2023.11.27.06.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:56:10 -0800 (PST) From: Christoph Muellner To: libc-alpha@sourceware.org, Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH 2/2] RISC-V: Attempt to enable TSO mode for TSO binaries Date: Mon, 27 Nov 2023 15:56:03 +0100 Message-ID: <20231127145603.2339644-3-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231127145603.2339644-1-christoph.muellner@vrull.eu> References: <20231127145603.2339644-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.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. A RFC kernel patchset has been posted that provides a prctl API to get and set the current consistency model. This patch attempts to switch to the TSO consistency model in case the ELF file requires a TSO machine and the machine does not run in TSO mode. If the attempt fails, we fall back to the old behaviour and claim that the ELF file is not compatible with the host. Signed-off-by: Christoph Müllner --- sysdeps/riscv/dl-machine.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index ce537731dd..65be660a76 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -72,9 +73,19 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) return 0; #endif - /* Execution of TSO binaries is not supported at this time. */ + /* Execution of TSO binaries depends on machine's consistency model. */ if (ehdr->e_flags & EF_RISCV_TSO) - return 0; + { + /* Attempt to get current consistency model. */ + int ret = prctl(PR_GET_MEMORY_CONSISTENCY_MODEL); + if (ret == -1) + return 0; + /* If we have a mismatch, let's try to switch to TSO. */ + if (ret != PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO && + prctl(PR_SET_MEMORY_CONSISTENCY_MODEL, + PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO)) + return 0; + } return 1; }