From patchwork Fri Dec 22 07:46:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13503072 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 52BDCC41535 for ; Fri, 22 Dec 2023 07:46:49 +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:References:In-Reply-To: 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: List-Owner; bh=4qZEtzStyMF0Jcfhs1ES32ykaEww9oQ7q4Fil/EN7BA=; b=DTdedIjXqc910Z n94OHleWAxA5Pv6/VISqyL8vR0DstNUQadR2GVoOVuEDUEBrlheTEV5E2LaPYtI7bQofcY0l6Qh1/ 77RzkDh8t3FFpzHjI7VxYngptVw6QlilkDY+8iig32IcD0Cx/s76aO71SaCZl2mAv+qdy8DG5J0er Sd8MeUnJmF7FUb19ZlnSG2vooQI7iWoa3UHDlpByftAiQq+0vy+17rcg/czXxqU7eB3p7zSEAEpGr rXMCZMo9XExjfBf+ZSzXVXIJD+oMgZNqYmHTsNw3TDPG/0y0FmMm9SuFqb7Xcs3fLF8Iq97NY1/Zo 4fsWowEKxSvgl1AdJPwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGaF2-005DDv-12; Fri, 22 Dec 2023 07:46:44 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGaEz-005DAV-1T for linux-riscv@lists.infradead.org; Fri, 22 Dec 2023 07:46:43 +0000 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9dWOLJ/7H2GD4Bb9fMRINczeyfjJ7YRASwlhClz2V/8=; b=gjULgw2ERygmkaSCWZ7fwpOSzXijqvBwPgrmxOT0ZhgsuhWah0uN1KWg7yLigInYPCern+ aC7fAbNmcDUlPl0xFez5KKBTeOifSLNDoyjHyCNFojrCz4INkM6NxDeC0aaPkZg9TdrpoP jvYI9npEoHtg3xmZDKAhem3mNyqHGj8= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-k4t6QOfgODi9Gxip47VZXQ-1; Fri, 22 Dec 2023 02:46:37 -0500 X-MC-Unique: k4t6QOfgODi9Gxip47VZXQ-1 Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-3bb7ab55483so1672020b6e.1 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=AjSJtKfRfPVNOv0kq36/kRcfOA4ioZOxm+JUftmkh++fCA8mp7kXY7O+O8FcUbQvsf 00PzSmscJ4Y/P87afssOG0dYTxKhFsvzSFPB14iJxCF5jBJzpTqYtYQiFK7dAl6LnuTE uVyJPaBApe3ljpufCvUWVHaLR7iVEKrsOfzWo1LsIPvEP4vIAhzVyNjFrnqYdZGhW5cs r9fhPxUjb2SzOsnTqWe+sqsfYufY1cw38aes+5MbROoG0EkZ323Nc8yV31iPjhQ8eeuB RW/yLPUbPgTV53m94p9PUMwaAF9OJE6wONoOUCrYkb7ZHRCnQIReN4lHy35N2WTAq9Az CVkg== X-Gm-Message-State: AOJu0Yy2lWJYjofMxVDW5Wc7DB8BWl4A7TwDp7r8z9jqd9F6+uqsRoQA eibTBazjrQKOiPcjVS+5uyK4Z8koNCcKde+fBbRtX58nIxMU/liEzHQDJLGNgNEm6Me/nLEsysa GcZnW4AHfYDtmCUc/eAT1ETO/BFGBq4rqjNpv X-Received: by 2002:a05:6808:218e:b0:3a8:7c67:7cd with SMTP id be14-20020a056808218e00b003a87c6707cdmr1261200oib.24.1703231196636; 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?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , 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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_234641_573684_8591B997 X-CRM114-Status: GOOD ( 12.57 ) 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 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); #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/pgtable.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) #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 From patchwork Fri Dec 22 07:46:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13503073 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 DC537C46CD4 for ; Fri, 22 Dec 2023 07:46:53 +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:References:In-Reply-To: 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: List-Owner; bh=ZSlH7+ulBLaHhcNIbQiwPJ4j9ORU7RyiqHWZdOKpWfQ=; b=e1bcy3fCrl+MEQ 4OlglaPXepz8Cn3ZAG+S2HjyfHeBE3NAeSuS35/HXnyXmr0up6R3BwBm/DqvfUIHIdrmqqkQ99VQC BlELg/vvFhdC0Ksval/+iHhYiQbbAiGZTL+7iqlFtcwyAf1s2URvGqKwwobElHhgqHzjM1dyr6CjP K23TmFukjscP914YI2e+YI6C6u0crRUPvx9kL7w6FJ7zwQX7K8ybeuZBwRklzXeMI0ii1jm/6NwEQ 5zITNOlFc5BpJUXcrz339BvZhmuGialpx3a1EGcRarzb7zrJJHJqjK1LalsPZAHmiV6TapvXvtImG 2gMccU1n5Ik3KMvStQ4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGaF6-005DFi-05; Fri, 22 Dec 2023 07:46:48 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGaF3-005DEO-2z for linux-riscv@lists.infradead.org; Fri, 22 Dec 2023 07:46:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703231205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fChu8SySxAk9bR4FCWD8rViiukJB4FWPqrqCbBPM0wY=; b=JkclaATlqcDTBMl3lET/EcIBS0BqVnmX764h8/53EVuTGRhYDzmKirkp44P8uWYGmBRvHV 32rABgyuocvKtRV/BaGvKqOhO2fuHfyoFaNZBTmFpIuUZWIcHTxJpSGOWDWCRE21h+5pBq CbrZTL2nY37orpLLcLfEgnLchS+x/vo= 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-452-j7NxmmnhOtOnKzEVaRSsFQ-1; Fri, 22 Dec 2023 02:46:43 -0500 X-MC-Unique: j7NxmmnhOtOnKzEVaRSsFQ-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3b9fe1a9f16so1729913b6e.3 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=iKDJh/8+5l5jV6OEAM7nxa9X35I9N2HDJe/WmZKA501hbN9GKhBc+71lhins7OfPEt LLMQqXrMiSKXnVCTmIKaMdBrR2B45RyfDVDjJdaDeDgb/Co9Q7KNUJnJruhL6xSVtscs Wgsrsmoz5exmyKYBwAFx+a4wgWThZJi8Eojqsx/2lA0OVa+ERfw9r1sUpWxzTn0L2iSs SE3/IfitEmtG55I3zklhE8oUmhm95xUBrjgh7ZYKSLAyfyjYVCB2RYUnNbCiGa/T8U1Y kH7twAeAQPxn8UfVTX3GjD+8DPjwDJvvU1YSmQQ6bjyiaoMXzwdtqwF5g5HaXGkAYDnx mp+g== X-Gm-Message-State: AOJu0Yyzcy4o3tPTjn94gBjWoeyBRuZ5b/4GtIfKb3nBXrvf0j2PC5ca iDS5EIR19K2PmQCuYpBJVlwuMgOxiArJPuJJV2WBeNJot32bUqvF8iJhTBahpzRmLOvt1HXLmkh 82lirjszhdqIM643Ap9E6PyJLIFz97x9QGM80 X-Received: by 2002:a05:6808:199e:b0:3af:9838:8494 with SMTP id bj30-20020a056808199e00b003af98388494mr1174160oib.20.1703231202607; 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?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , 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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_234646_038249_7E600B4F X-CRM114-Status: GOOD ( 18.30 ) 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 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: Guo Ren Reviewed-by: Andy Chiu --- 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/compat.h index 2ac955b51148f..91517b51b8e27 100644 --- a/arch/riscv/include/asm/compat.h +++ b/arch/riscv/include/asm/compat.h @@ -14,6 +14,9 @@ static inline int is_compat_task(void) { + if (!IS_ENABLED(CONFIG_COMPAT)) + return 0; + return test_thread_flag(TIF_32BIT); } 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) #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 /* diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.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)) -#ifdef CONFIG_COMPAT #define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS) #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_BITS_64) -#else -#define MMAP_VA_BITS ((VA_BITS >= 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/processor.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 = (addr); \ - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + if ((_addr) == 0 || is_compat_task()) \ mmap_end = STACK_TOP_MAX; \ else if ((_addr) >= VA_USER_SV57) \ mmap_end = STACK_TOP_MAX; \ @@ -39,7 +39,7 @@ typeof(addr) _addr = (addr); \ typeof(base) _base = (base); \ unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \ - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + if ((_addr) == 0 || is_compat_task()) \ mmap_base = (_base); \ else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \ mmap_base = VA_USER_SV57 - rnd_gap; \ From patchwork Fri Dec 22 07:46:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13503074 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 24ED7C46CD8 for ; Fri, 22 Dec 2023 07:47: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:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=tW9mKQjQ4lHB4bKNay+CXh6Z80KPK+9xzojR7ujZtnY=; b=Ue/Y2iqtpNQLfI 2SkjEMP+sMec2in0XG7R0ZdWXO/G3TR0og7GOJs4/aRKk1DmPi0i9Rm+aNHEJNBo5TzzEPol19275 MnNFs1+qB0XAAV8PKLjHxK3tarNlMQFzHY+OSgiQKtdPBcx6wcv2afEOzNUIoFt9gmOglTdWfwYjY UCiVN9KP53N2SRWva16/QUaCrZcC57Xyg4wloMmt1RhZHICtOvhbT2Rzq2r8IRBu1xi6e6TqgcflR YopPA8MmzpRIlaGjqfTshfeEWyG3xbLHX48ieAXtl9U4MA2OMnje5ZwjskqpWUlXFJzjva8B0m2GH cQ/giOAeubw3FtLIO0lA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGaFD-005DLM-2r; Fri, 22 Dec 2023 07:46:55 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGaFA-005DHv-1H for linux-riscv@lists.infradead.org; Fri, 22 Dec 2023 07:46:54 +0000 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CivPyX79A0Z1hBiu+NIjR9u/sMwnUQBrdiWOV2RqYZw=; b=eZODkezzb3ZKdOlfJTCPfoqEPQWfs5NbXT3WfZwSLeRmx8ds6PiSy0elxsDmmm/V646e+4 YWsvq+ntrYAI+YtYEIvUzaUU45Rt9HaudtCXUqq7Q7gkckigAMXuZL5VKWcm4PAXu4uTUa uab5dZaYUdnlW/sIH7AZFD4S/dZjvfo= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-C5VC44DHP5GPisyDwcanSg-1; Fri, 22 Dec 2023 02:46:49 -0500 X-MC-Unique: C5VC44DHP5GPisyDwcanSg-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6d398f0de98so934591b3a.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=l2oqn9TC/NSxHdLadGO0SQxMK56xSIfDWbS/5DyQxTFAA5thf1/1ISalKsyVqzd9cb 89LWm552h1UNdH+/ZnmRTMcqBeQOxBi26AkdfEYkd8YfB6z5lICpgQ2sBQrL11XTWBmB 1nOadt1YisKPmX0HPSBE2eYiyfs/LVRSFeNzEF7brhe0aYLo1trIkx9UMFN6kcQa381s JJawiJkGyESUI3UBJOMMbxd2xxoEj1AhT2glUVcu4MV9Wc2MNgcEGvm3ZxbOZsuL6BIL fz2idcHcCJ+oR/NU0cuedumvuYTpwdc8MTNa14gAzoDwgqtY+EHmFXlHnnbLN1mSBfxo H9QA== X-Gm-Message-State: AOJu0YxHcaU0kqz3CLHQ9UkBmzISYGcX97CHDcIi3wLlNZ4VTX1RAl08 3wjXQoWERc/oB1XrDZ8h8/fzU3hW+8NOLxlfbaj4IimqLCA1QGJ5JZ3ZvYrMcgypWZRjGzTxsIV ibIhzvd9+LR6E9QGvlMhVMUjlktRMtWAhWp+1 X-Received: by 2002:aa7:930c:0:b0:6d9:6261:919e with SMTP id cz12-20020aa7930c000000b006d96261919emr591302pfb.19.1703231208654; 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?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , 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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_234652_502635_F1F0D3E7 X-CRM114-Status: GOOD ( 14.21 ) 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 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: Guo Ren Reviewed-by: Andy Chiu --- 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/compat.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); } +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, compat_long_t request, return ret; } +#else +static const struct user_regset_view compat_riscv_user_native_view = {}; #endif /* CONFIG_COMPAT */ const struct user_regset_view *task_user_regset_view(struct task_struct *task) { -#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; } From patchwork Fri Dec 22 07:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13503075 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 CFB0AC41535 for ; Fri, 22 Dec 2023 07:47:07 +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:References:In-Reply-To: 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: List-Owner; bh=CnPuL75jiU5q04YNj7IVC6hPDXM5n0aoKCLrWh1c9rc=; b=q1ugf2NKUZiCrS x09TKETLTcyzumdWvhQOy6J6mBlQ1DXk0Wfbs4n4n2QxZStgrSZ6Sl3iOjShEsOeFlxuNxruMHkxH 0aKvKVlbhFT9eBnPZ1b7daMj6zM5QzrsmVoUkR/u/StjrohFpfuELjWea6XKYWG0vQ0Kp0Wuq2SUi q059/01Gdx58fXOr/lM2Le20zxMZcW7QJpgjTaDhirilD7IWSnSPBkZWYjJgXbHO/3o10ucmVN6VV Er5dF0EsYJUSkGMP8EftOliC6wRoWshETOUbT+P6/Ov5GwxzqS2aMOM0Nl76oSaouXgwAap+c44K4 aaoyIqwgxL9eVO1anXpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGaFK-005DPr-2U; Fri, 22 Dec 2023 07:47:02 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rGaFH-005DNO-36 for linux-riscv@lists.infradead.org; Fri, 22 Dec 2023 07:47:01 +0000 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-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nJKdTz0fBLuk4zNW5VLOm1jY/M0/StXJiYDFTohFsJw=; b=RcXVTPfzgaS25PMxz4QcBFxcNES86FdBLF4Mcc6Oyqt1XJMfp1W1PK6u0FEM87FS8886vJ pIj/VnLDshW8z5Cv6Ndz1HsPy3vVYoEPwnKpREb5h51pPRU0uML8jchWba4Rs50SWN8nJQ CJrQqIbf2Vvt+MBZFQ5jUy2r0cBBmSc= 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-682-zm7DUoIpMlaVo9dGIyhG0A-1; Fri, 22 Dec 2023 02:46:55 -0500 X-MC-Unique: zm7DUoIpMlaVo9dGIyhG0A-1 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-6d7e5d286a1so1180993b3a.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=1703231215; x=1703836015; 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=Q7vkMdsNMZ+9tMZ85X8/Pi5EmGApRXJfzwwMgqwyXn825sTTWW8Swy2fT6TsRle0bC avqDfxlgiUT0SVzOCFYyzWRX2wyky6E89GV0qAyFNBSU7ThqDYfCH5j0auG3d2dG/3/W MgzVH3as6G38WJVULk/dj/O5BYu7MvMPMlscaxIJJh3VHF9SWZm4xUKv1hFG45AhY0Vk F0O2UvsPxvYO9N5gH/qU4n9b0/zW8VBRycWhsIlytpxRwQkeDkHkcTMbyt/tom79kq7D kBGCbdDGOgPrVfOyCHNQnPGdqbLm9jQ6gqpYRVH/r3R5Q7IYw9pWjNMUrxp1K3J1lfcX Jrnw== X-Gm-Message-State: AOJu0YxOVqXH/ucM70W7XCc++xEbYe3vr43L/w7ThrWsFJycFBMqrTPC /ZkudEaLP6Si88Juvwxmq6ol3ct/wxxAc2yA+kRaIPkfw9FxyTv0nhdHW9l09G8ls0wl3F2YOEd /923LL/vptzb7udkX+jQsiIwhllcxhWEFt0Md X-Received: by 2002:aa7:9104:0:b0:6d9:3659:5419 with SMTP id 4-20020aa79104000000b006d936595419mr998863pfh.21.1703231214632; 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?b?QmrDtnJuIFTDtnBlbA==?= , =?utf-8?b?Q2zDqW1l?= =?utf-8?b?bnQgTMOpZ2Vy?= , 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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_234700_068184_8B738CB7 X-CRM114-Status: GOOD ( 12.23 ) 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 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/compat.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 *thread) return test_ti_thread_flag(thread, TIF_32BIT); } +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 #define SET_PERSONALITY(ex) \ -do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ - set_thread_flag(TIF_32BIT); \ - else \ - clear_thread_flag(TIF_32BIT); \ +do { set_compat_task((ex).e_ident[EI_CLASS] == ELFCLASS32); \ if (personality(current->personality) != PER_LINUX32) \ set_personality(PER_LINUX | \ (current->personality & (~PER_MASK))); \