From nobody Fri Dec 19 17:01:18 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 BE2A4D314 for ; Fri, 22 Dec 2023 07:46:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Iq2zGoSK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703231199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9dWOLJ/7H2GD4Bb9fMRINczeyfjJ7YRASwlhClz2V/8=; b=Iq2zGoSKQSWdk4hTQMf8ktPKTSupPZE5YmvnaZlmwddmDIexjuLYAcNO1od/0VTl8MFDFD L5Hy0OvpBDG5oaIgntWztH27Narxw1LVwZmClEQWCdTOvZwFwakmkglAGcbIdwuGMnu3Rc IVtVbSF5oB0h735hpIoX5Wfk63E74XI= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-fOCNbyuzNSGv0oZDyO8J8A-1; Fri, 22 Dec 2023 02:46:37 -0500 X-MC-Unique: fOCNbyuzNSGv0oZDyO8J8A-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3bb879ac903so690234b6e.3 for ; Thu, 21 Dec 2023 23:46:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703231196; x=1703835996; 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=9dWOLJ/7H2GD4Bb9fMRINczeyfjJ7YRASwlhClz2V/8=; b=V0330JZ6jl3/FJzkAmWi0pEKvPC1Bw4tbfhDnHbb84FxEMZi2UlBIM4Db8I4Umb0+8 aup+uIdPab8/upOoefMLN8p9XIsUYZ4cBLll97OLbBxmwV9pV3ShKDeDt8NsO3Lzpm9w y7OvBGudO7Df+39T8g1DrvydWV633OKkfk6vSEgDKi0m6O/Ln3Zsuto+hZWk/SpRiCtV ynmOxF7LeErM5UgUU1CpnU35mrDs7qmdOzaLucyPphwZEYWj2JRHwdmDVi5mxAcq73jU xBeMyc0aS5dViiheVKC+9Vycww25HjCueuxhPxtqMgfwTCFtbTWQLOeFI36Ca2p0xO1/ DSWQ== X-Gm-Message-State: AOJu0Yy4GuAI+EBtney0fvfs3wa3aTc8teXYTPPxTfqfZ98rO4r5WGxX YmwrNBMCj2bLVfmQyHiGYV3rydkjTFfAm/3J4He1LW57hFOUzvngimlOeMJrJNx01k5S5TimgZC 0FtCD9KTxAZe94FBA1HQTKTGK/bbd5/Wg X-Received: by 2002:a05:6808:218e:b0:3a8:7c67:7cd with SMTP id be14-20020a056808218e00b003a87c6707cdmr1261191oib.24.1703231196634; Thu, 21 Dec 2023 23:46:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6noE7Pu5xAXvjh6CjMsnvaqxm6CqicXC5ZlFE2NmSpCIPLtETaqNzkTmN5ZP4z5PF3/bRXQ== X-Received: by 2002:a05:6808:218e:b0:3a8:7c67:7cd with SMTP id be14-20020a056808218e00b003a87c6707cdmr1261182oib.24.1703231196440; Thu, 21 Dec 2023 23:46:36 -0800 (PST) Received: from localhost.localdomain ([2804:1b3:a802:7496:88a7:1b1a:a837:bebf]) by smtp.gmail.com with ESMTPSA id m2-20020a62f202000000b006d97eaba6cesm1527015pfh.21.2023.12.21.23.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:46:35 -0800 (PST) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Leonardo Bras , Conor Dooley , Andy Chiu , Greg Ungerer , Vincent Chen , Xiao Wang , Charlie Jenkins , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 1/4] riscv: Replace direct thread flag check with is_compat_task() Date: Fri, 22 Dec 2023 04:46:01 -0300 Message-ID: <20231222074605.452452-2-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231222074605.452452-1-leobras@redhat.com> References: <20231222074605.452452-1-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is some code that detects compat mode into a task by checking the flag directly, and other code that check using the helper is_compat_task(). Since the helper already exists, use it instead of checking the flags directly. Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/elf.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index 06c236bfab53b..59a08367fddd7 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -54,7 +54,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); =20 #ifdef CONFIG_64BIT #ifdef CONFIG_COMPAT -#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \ +#define STACK_RND_MASK (is_compat_task() ? \ 0x7ff >> (PAGE_SHIFT - 12) : \ 0x3ffff >> (PAGE_SHIFT - 12)) #else diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgta= ble.h index ab00235b018f8..1d472b31e0cfe 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -882,7 +882,7 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) =20 #ifdef CONFIG_COMPAT #define TASK_SIZE_32 (_AC(0x80000000, UL) - PAGE_SIZE) -#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \ +#define TASK_SIZE (is_compat_task() ? \ TASK_SIZE_32 : TASK_SIZE_64) #else #define TASK_SIZE TASK_SIZE_64 --=20 2.43.0 From nobody Fri Dec 19 17:01:18 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 CCFB0FBF2 for ; Fri, 22 Dec 2023 07:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VOqgnlPb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703231204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fChu8SySxAk9bR4FCWD8rViiukJB4FWPqrqCbBPM0wY=; b=VOqgnlPb7koRbqdmNp7zwu4MFdgWKsXehtMUmpNMvOac54cUPnSl/uTy5tLGf9Y7RqzRKb wkIddCPpfTGOYVY22/9SvoHv96YJWg8M1sIeV4spTUWg28A7C5M0nyV62OvRiGA9qALJTv i6Agmad/bUVySI3vGrIsFSTyBQuRvuk= Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-ov2EwXhaOC6oJINNVIaiXQ-1; Fri, 22 Dec 2023 02:46:43 -0500 X-MC-Unique: ov2EwXhaOC6oJINNVIaiXQ-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-3b9dff5942fso1730067b6e.2 for ; Thu, 21 Dec 2023 23:46:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703231202; x=1703836002; 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=fChu8SySxAk9bR4FCWD8rViiukJB4FWPqrqCbBPM0wY=; b=fuD38Irh04LN21FU7P9Y8saUaoEOQ0P6CJ1fsZGulplvuYiS9oxdsMnd66Qyp1mrgv hcIxSuozNpwBteZKwuDpUTYxvIQ37VJPNs8k2KwtFwXavQopQXGNAfcEjHxXwMQwehKY LrPxWjIzmNn/8WT1ZAHoo+CvnHfIKjOPzXCQ/MZ0xZpEH/y+qnBJ+nmMyopFo7pKrhcw 7u3KU+jelJ8zs9zrmUIyv47+RxaxUhpmjEcSaawDEv283p7N5i5m5nF+n1rOheJcEOMG 7r8wisiJOBi6pf58vD/eio6CQtYcSh2O+k+/zEFquqzrEt6zB8GgPOo3BicMdQ7r+nS5 CKXw== X-Gm-Message-State: AOJu0YwuNXEyrMquWHQIoIJJIIgCr/QiJLKmOx8pzoUiBt+SPpDKbcmo kiL9mxN7Suat7HvCZw15G790Nv8X7W/va2FBR9PPvaYcOAoeSowuBs+ZkpE9BbmsihPOwSu84RD myTk/ZH+Jtk3rpruXf93L3oquZuFtKv5U X-Received: by 2002:a05:6808:199e:b0:3af:9838:8494 with SMTP id bj30-20020a056808199e00b003af98388494mr1174140oib.20.1703231202597; Thu, 21 Dec 2023 23:46:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfty2NP0/+vK/Z37DtQxU8NTNsz0hOUOMzPkaafOkXIkbGg41CPwcD8fDjKPqNGVFT8AzCRw== X-Received: by 2002:a05:6808:199e:b0:3af:9838:8494 with SMTP id bj30-20020a056808199e00b003af98388494mr1174135oib.20.1703231202376; Thu, 21 Dec 2023 23:46:42 -0800 (PST) Received: from localhost.localdomain ([2804:1b3:a802:7496:88a7:1b1a:a837:bebf]) by smtp.gmail.com with ESMTPSA id m2-20020a62f202000000b006d97eaba6cesm1527015pfh.21.2023.12.21.23.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:46:41 -0800 (PST) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Leonardo Bras , Conor Dooley , Andy Chiu , Greg Ungerer , Vincent Chen , Xiao Wang , Charlie Jenkins , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/4] riscv: add compile-time test into is_compat_task() Date: Fri, 22 Dec 2023 04:46:02 -0300 Message-ID: <20231222074605.452452-3-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231222074605.452452-1-leobras@redhat.com> References: <20231222074605.452452-1-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently several places will test for CONFIG_COMPAT before testing is_compat_task(), probably in order to avoid a run-time test into the task structure. Since is_compat_task() is an inlined function, it would be helpful to add a compile-time test of CONFIG_COMPAT, making sure it always returns zero when the option is not enabled during the kernel build. With this, the compiler is able to understand in build-time that is_compat_task() will always return 0, and optimize-out some of the extra code introduced by the option. This will also allow removing a lot #ifdefs that were introduced, and make the code more clean. Signed-off-by: Leonardo Bras Reviewed-by: Andy Chiu Reviewed-by: Guo Ren --- arch/riscv/include/asm/compat.h | 3 +++ arch/riscv/include/asm/elf.h | 4 ---- arch/riscv/include/asm/pgtable.h | 6 ------ arch/riscv/include/asm/processor.h | 4 ++-- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compa= t.h index 2ac955b51148f..91517b51b8e27 100644 --- a/arch/riscv/include/asm/compat.h +++ b/arch/riscv/include/asm/compat.h @@ -14,6 +14,9 @@ =20 static inline int is_compat_task(void) { + if (!IS_ENABLED(CONFIG_COMPAT)) + return 0; + return test_thread_flag(TIF_32BIT); } =20 diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index 59a08367fddd7..2e88257cafaea 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -53,13 +53,9 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); #define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2) =20 #ifdef CONFIG_64BIT -#ifdef CONFIG_COMPAT #define STACK_RND_MASK (is_compat_task() ? \ 0x7ff >> (PAGE_SHIFT - 12) : \ 0x3ffff >> (PAGE_SHIFT - 12)) -#else -#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) -#endif #endif =20 /* diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgta= ble.h index 1d472b31e0cfe..ea5b269be223a 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -127,16 +127,10 @@ #define VA_USER_SV48 (UL(1) << (VA_BITS_SV48 - 1)) #define VA_USER_SV57 (UL(1) << (VA_BITS_SV57 - 1)) =20 -#ifdef CONFIG_COMPAT #define MMAP_VA_BITS_64 ((VA_BITS >=3D VA_BITS_SV48) ? VA_BITS_SV48 : VA_B= ITS) #define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39) #define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64) #define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BI= TS_64) -#else -#define MMAP_VA_BITS ((VA_BITS >=3D VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS) -#define MMAP_MIN_VA_BITS (VA_BITS_SV39) -#endif /* CONFIG_COMPAT */ - #else #include #endif /* CONFIG_64BIT */ diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/pr= ocessor.h index f19f861cda549..ed32e53e55999 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -22,7 +22,7 @@ ({ \ unsigned long mmap_end; \ typeof(addr) _addr =3D (addr); \ - if ((_addr) =3D=3D 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + if ((_addr) =3D=3D 0 || is_compat_task()) \ mmap_end =3D STACK_TOP_MAX; \ else if ((_addr) >=3D VA_USER_SV57) \ mmap_end =3D STACK_TOP_MAX; \ @@ -39,7 +39,7 @@ typeof(addr) _addr =3D (addr); \ typeof(base) _base =3D (base); \ unsigned long rnd_gap =3D DEFAULT_MAP_WINDOW - (_base); \ - if ((_addr) =3D=3D 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + if ((_addr) =3D=3D 0 || is_compat_task()) \ mmap_base =3D (_base); \ else if (((_addr) >=3D VA_USER_SV57) && (VA_BITS >=3D VA_BITS_SV57)) \ mmap_base =3D VA_USER_SV57 - rnd_gap; \ --=20 2.43.0 From nobody Fri Dec 19 17:01:18 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 6C13812E6C for ; Fri, 22 Dec 2023 07:46:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AMnEk8kU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703231211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CivPyX79A0Z1hBiu+NIjR9u/sMwnUQBrdiWOV2RqYZw=; b=AMnEk8kUg/IEB2ajMx/nMXqXatiwWDNW6eL5FAG95fFqCzO+Kj5xjReD+EsIIFQLUBGFJn Bzl1VysEDs7JJ0evp1EW1XhhJJ3uij+oDKXgkVMLXviB+W2b96HqYPO/+Ne1J59gzNnWSd 2buRqakCQ2Rvwa/DBfwPlUu0GJqW0UM= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-PiVJaWRtPwOz4x9bUx9z3Q-1; Fri, 22 Dec 2023 02:46:49 -0500 X-MC-Unique: PiVJaWRtPwOz4x9bUx9z3Q-1 Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-6d398f0de98so934589b3a.2 for ; Thu, 21 Dec 2023 23:46:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703231208; x=1703836008; 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=CivPyX79A0Z1hBiu+NIjR9u/sMwnUQBrdiWOV2RqYZw=; b=IR9/Fko9pedkzvA9GtKNHcMUrwX0mzpfBBp8EujkcjhlA7oaTKowxbvI+6UHvTmHQE avz5n9PlEK3BmiJaUboeU29orP+OU1rg8Ej8A8SKWYTg4qubRT5uOo0q6dRoGyjGSX7K YU8bRCvw75FncYmeer4K3Dy2xtx6Km3AxOIPLPp7833WIkk3MxCvuGZHhmH1/KnZlVYp Uibl+VGoA3hO9jbLdHPNKqn5os9k9HnOcgF5GtFvvJJP/2mEagwcF/MeHsDtnwNEvSnM 2X4HLELKgOBkJKaHfd8fkd3ksgzT65A6fuSFR1sPSVRQSxrS5OYnRFCkirveiMcbmLvB vbog== X-Gm-Message-State: AOJu0YzmNFKKr2mmEpY+Dwe+Uxtq6bf8f+JOHSXnPu1Ypy+OGPMjTmYT FQkKE8tylZMeEXqjikvRFXsEJ+9uLeidcS9wtdSL5mVdKdP3+zxUgA2N7fjaW7ov0e7DWNV4+FX UFA2kCK6+vFA1JLewc5FEfrLLjOF5YmxN X-Received: by 2002:aa7:930c:0:b0:6d9:6261:919e with SMTP id cz12-20020aa7930c000000b006d96261919emr591296pfb.19.1703231208652; Thu, 21 Dec 2023 23:46:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3ju0vDAUEHX0GCDDvkiFL8Wq0IKN/wM1vpTmL1pxShU1txvq7JIxARGiDwyFtjeAX5+gIOw== X-Received: by 2002:aa7:930c:0:b0:6d9:6261:919e with SMTP id cz12-20020aa7930c000000b006d96261919emr591291pfb.19.1703231208347; Thu, 21 Dec 2023 23:46:48 -0800 (PST) Received: from localhost.localdomain ([2804:1b3:a802:7496:88a7:1b1a:a837:bebf]) by smtp.gmail.com with ESMTPSA id m2-20020a62f202000000b006d97eaba6cesm1527015pfh.21.2023.12.21.23.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:46:47 -0800 (PST) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Leonardo Bras , Conor Dooley , Andy Chiu , Greg Ungerer , Vincent Chen , Xiao Wang , Charlie Jenkins , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 3/4] riscv: Introduce is_compat_thread() into compat.h Date: Fri, 22 Dec 2023 04:46:03 -0300 Message-ID: <20231222074605.452452-4-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231222074605.452452-1-leobras@redhat.com> References: <20231222074605.452452-1-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" task_user_regset_view() makes use of a function very similar to is_compat_task(), but pointing to a any thread. In arm64 asm/compat.h there is a function very similar to that: is_compat_thread(struct thread_info *thread) Copy this function to riscv asm/compat.h and make use of it into task_user_regset_view(). Also, introduce a compile-time test for CONFIG_COMPAT and simplify the function code by removing the #ifdef. Signed-off-by: Leonardo Bras Reviewed-by: Andy Chiu Reviewed-by: Guo Ren --- arch/riscv/include/asm/compat.h | 8 ++++++++ arch/riscv/kernel/ptrace.c | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compa= t.h index 91517b51b8e27..da4b28cd01a95 100644 --- a/arch/riscv/include/asm/compat.h +++ b/arch/riscv/include/asm/compat.h @@ -20,6 +20,14 @@ static inline int is_compat_task(void) return test_thread_flag(TIF_32BIT); } =20 +static inline int is_compat_thread(struct thread_info *thread) +{ + if (!IS_ENABLED(CONFIG_COMPAT)) + return 0; + + return test_ti_thread_flag(thread, TIF_32BIT); +} + struct compat_user_regs_struct { compat_ulong_t pc; compat_ulong_t ra; diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c index 2afe460de16a6..f362832123616 100644 --- a/arch/riscv/kernel/ptrace.c +++ b/arch/riscv/kernel/ptrace.c @@ -374,14 +374,14 @@ long compat_arch_ptrace(struct task_struct *child, co= mpat_long_t request, =20 return ret; } +#else +static const struct user_regset_view compat_riscv_user_native_view =3D {}; #endif /* CONFIG_COMPAT */ =20 const struct user_regset_view *task_user_regset_view(struct task_struct *t= ask) { -#ifdef CONFIG_COMPAT - if (test_tsk_thread_flag(task, TIF_32BIT)) + if (is_compat_thread(&task->thread_info)) return &compat_riscv_user_native_view; else -#endif return &riscv_user_native_view; } --=20 2.43.0 From nobody Fri Dec 19 17:01:18 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 2163D168BE for ; Fri, 22 Dec 2023 07:47:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DjqhbIJk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703231219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nJKdTz0fBLuk4zNW5VLOm1jY/M0/StXJiYDFTohFsJw=; b=DjqhbIJkAZIEPaWhWuFyQGNUdeYwTj0hTQnUIVtDgcPkeXJ7bfsoTz8icwKLhT6ie39ZuG wvx1GILBYCAOYG23jDPEj450wV1cmzb+Nl1p7Nwz9rG/XHL+ZqIUyYrGr7PEbNaaagr9sP r8+rAeNnjZ3zom/0YACulcoYrF04SNs= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-XAa0y1LIPzytKDxcP7-IuA-1; Fri, 22 Dec 2023 02:46:55 -0500 X-MC-Unique: XAa0y1LIPzytKDxcP7-IuA-1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-6d7e5d286a1so1180982b3a.1 for ; Thu, 21 Dec 2023 23:46:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703231214; x=1703836014; 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=nJKdTz0fBLuk4zNW5VLOm1jY/M0/StXJiYDFTohFsJw=; b=i1Bl+5T455m0DeJuHcgKsa7lMxa6Vqd53sLJFu9bp1RuA6JaeW5ptp28tfy+Y/7kfi qeH85Qu8cRmqlPeJRjLieyOUK05um8OtmzT+T5dE9u/Ab4zWT3PE9sRoC/d3FeUI9Ufb aHbDlVf8wGkajcrx8ATRm47fEHNahDh1GXpeMkWvdjkgdDjJOHmWOzFWmOW6eWvzCfHK Sfbjr3BW2LnLUFN4nuSfLczlXGF9JWRZMhKs/xIKY9io5qwqNb4gltIGgrEpKF3yJ+BW iaG8rNcq0pe0L185/25cOGoXCF05luZ7KJtUwAIycT1FnLCgOofoHUMjErXDgwGO3A+e y1dw== X-Gm-Message-State: AOJu0YxD2XX4AjnK9cOtPlAEMlDweM5KewcL1k9mc9j3Y7rDleGIpB3z qq04yLOmNLr4EKWx8JWh0CnGi3qvnEr4boqVOwdf6BdncB1QFv0qoKIM585Tts5ko6p+32W4aHu Lno9sw9ikzjG9f0DM+FG5EwIHOwQv5Z9P X-Received: by 2002:aa7:9104:0:b0:6d9:3659:5419 with SMTP id 4-20020aa79104000000b006d936595419mr998852pfh.21.1703231214628; Thu, 21 Dec 2023 23:46:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMFmEyFRjwKSQRTyr1Tjdg/8FK7+G5rpG28wVcUI80rZUZeycJ9jxcUGtZ0nSOM5ugBFakSg== X-Received: by 2002:aa7:9104:0:b0:6d9:3659:5419 with SMTP id 4-20020aa79104000000b006d936595419mr998837pfh.21.1703231214349; Thu, 21 Dec 2023 23:46:54 -0800 (PST) Received: from localhost.localdomain ([2804:1b3:a802:7496:88a7:1b1a:a837:bebf]) by smtp.gmail.com with ESMTPSA id m2-20020a62f202000000b006d97eaba6cesm1527015pfh.21.2023.12.21.23.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:46:53 -0800 (PST) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Leonardo Bras , Conor Dooley , Andy Chiu , Greg Ungerer , Vincent Chen , Xiao Wang , Charlie Jenkins , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 4/4] riscv: Introduce set_compat_task() in asm/compat.h Date: Fri, 22 Dec 2023 04:46:04 -0300 Message-ID: <20231222074605.452452-5-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231222074605.452452-1-leobras@redhat.com> References: <20231222074605.452452-1-leobras@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to have all task compat bit access directly in compat.h, introduce set_compat_task() to set/reset those when needed. Also, since it's only used on an if/else scenario, simplify the macro using it. Signed-off-by: Leonardo Bras Reviewed-by: Guo Ren --- arch/riscv/include/asm/compat.h | 8 ++++++++ arch/riscv/include/asm/elf.h | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compa= t.h index da4b28cd01a95..aa103530a5c83 100644 --- a/arch/riscv/include/asm/compat.h +++ b/arch/riscv/include/asm/compat.h @@ -28,6 +28,14 @@ static inline int is_compat_thread(struct thread_info *t= hread) return test_ti_thread_flag(thread, TIF_32BIT); } =20 +static inline void set_compat_task(bool is_compat) +{ + if (is_compat) + set_thread_flag(TIF_32BIT); + else + clear_thread_flag(TIF_32BIT); +} + struct compat_user_regs_struct { compat_ulong_t pc; compat_ulong_t ra; diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index 2e88257cafaea..c7aea7886d22a 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -135,10 +135,7 @@ do { \ #ifdef CONFIG_COMPAT =20 #define SET_PERSONALITY(ex) \ -do { if ((ex).e_ident[EI_CLASS] =3D=3D ELFCLASS32) \ - set_thread_flag(TIF_32BIT); \ - else \ - clear_thread_flag(TIF_32BIT); \ +do { set_compat_task((ex).e_ident[EI_CLASS] =3D=3D ELFCLASS32); \ if (personality(current->personality) !=3D PER_LINUX32) \ set_personality(PER_LINUX | \ (current->personality & (~PER_MASK))); \ --=20 2.43.0