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: 13503069 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0193FC41535 for ; Fri, 22 Dec 2023 07:46:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58D226B007E; Fri, 22 Dec 2023 02:46:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 534026B0080; Fri, 22 Dec 2023 02:46:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B47B6B0081; Fri, 22 Dec 2023 02:46:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 272886B007E for ; Fri, 22 Dec 2023 02:46:54 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F11CFA0738 for ; Fri, 22 Dec 2023 07:46:53 +0000 (UTC) X-FDA: 81593672706.17.7EEC2FE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id DB923C0002 for ; Fri, 22 Dec 2023 07:46:51 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eZODkezz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of leobras@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=leobras@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703231211; h=from:from:sender: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:dkim-signature; bh=CivPyX79A0Z1hBiu+NIjR9u/sMwnUQBrdiWOV2RqYZw=; b=6RgV9japp7eyuaNGT55Q3UVsa6Y8skZceu3xlrdGwS+WA44VWL9fimTfWWPJ1ygyR5zpc9 oqmu9F6WoVYOMFpI0MqrfeW92Izh4nBpsXFJ6lmrpUBtt6SKsIjTZ5R5dLWwoQ8INePKsS C/sJUPuGQkVGgyQNPnXvdkwE3rpgxTM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eZODkezz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of leobras@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=leobras@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703231211; a=rsa-sha256; cv=none; b=8bYIay8JAqToFpNxYSIPaTg7pmXOjEC/bHG/ZyMsTKEIaiHXpID78RZdZ2eC7Mm+RQYj/O xM5DvMxUzPcviHptQcKeGyPFHQAOoV6q7ZlSpTQBFbZSJpYV2gN4WxkGjG8YCafFhbX3kQ BtAgoMlljKvQyn/sxm/wQyhtfouZxiY= 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-nYGUPjvLNaiudHzB1MTaPA-1; Fri, 22 Dec 2023 02:46:49 -0500 X-MC-Unique: nYGUPjvLNaiudHzB1MTaPA-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6d26718254fso944359b3a.1 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=V5NQ0vl4ejYgOmR63aWFGcwQYyce7i92zrXalTX7ggc5Rw4iwWaEE6vOQX3AmnjXaX 7XgDW6dijF/XOUvjGxx/OMRyACgbCPs8+e79OyDUnymSv83jgI5LQiBd+Hvvm1R4MqWQ nNZZ9+MwRJAiWLCPAI2O5m6/4aUDTzdFXfcyviPPeXbAWU2lI+5327l8Iv5gnkQUfG+T Ce023Fu9ISvTIfy8ybAcIAs2ewXQUHZFv183IUTgjqk75gbvrQ0ICSOWUsfFZytIFyFL VbmDtJdnebHCzE3A/em1pH0LZZ5+9XAhFDDs6pC/GTbN6yhOuts4TOBBfEn27z6wt9mc jNnQ== X-Gm-Message-State: AOJu0YxHd88WYH7dDgRSFoVkEp2hUVnMAWSpZ2b63SLP2TzZjFMl8Usr tmAQp+Dl1yN3P/6TBoy3TGAgMiuQxUA/TkQXVJdIiiOofPSLM0oGl9+r5h9pvN0ojNs6Wp9o2Ng DDks1MFS2R27LBbNjKJ8= X-Received: by 2002:aa7:930c:0:b0:6d9:6261:919e with SMTP id cz12-20020aa7930c000000b006d96261919emr591314pfb.19.1703231208667; 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-Rspamd-Queue-Id: DB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2bId XukGZwJhtEhdTVML8bSyPoHMQfO1VAefxCOO2dkvwAHvQ62XsVClEfPbdZ8P4ncDeYVbvK08fJDE4HSdWCZGArfbRSMY2WQJ5X44Z9svIzaq0YnbPfIQJZOFuhBIAKGD9geS582oEjzfmjDAKNI0z2YCYWJjR182h23ZdfXDBv2044ROlv/TBbjMch+csZPZaVB5v+FtpXEwOcK+FlhJdIJb4Zjxx/47FCCghL79/oTYy7DhfHkv4dwwUuJSdfstMTXoIu8PhIc1nJiUvg7GEJ8XNTMKYYBhQH/j9EM+ox9xA1uUj3OzQ5yqSrI7jDJSF4WiouUi5dl6iU0RApPJix1vc1LhdDLHfxJzLsupOKa1lkQhGamcwy6IZ6zdz2Tpenht9KUbTEfGsbWa9h9TRUATaP3M/p+1U7xeRm24f69m2Iq4hA1vMa/UsQ9MZLdNdpKwa X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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; }