From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68887C433E2 for ; Mon, 22 Mar 2021 10:34:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31A816198F for ; Mon, 22 Mar 2021 10:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbhCVKeP (ORCPT ); Mon, 22 Mar 2021 06:34:15 -0400 Received: from foss.arm.com ([217.140.110.172]:57146 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbhCVKdq (ORCPT ); Mon, 22 Mar 2021 06:33:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 20A461063; Mon, 22 Mar 2021 03:33:45 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 99FEF3F718; Mon, 22 Mar 2021 03:33:44 -0700 (PDT) Subject: Re: [kvm-unit-tests PATCH 3/4] arm/arm64: Track whether thread_info has been initialized To: Nikos Nikoleris , kvm@vger.kernel.org Cc: drjones@redhat.com References: <20210319122414.129364-1-nikos.nikoleris@arm.com> <20210319122414.129364-4-nikos.nikoleris@arm.com> From: Alexandru Elisei Message-ID: <9325d09d-aa0b-0715-f013-8926de3673cb@arm.com> Date: Mon, 22 Mar 2021 10:34:14 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210319122414.129364-4-nikos.nikoleris@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Nikos, On 3/19/21 12:24 PM, Nikos Nikoleris wrote: > Introduce a new flag in the thread_info to track whether a thread_info > struct is initialized yet or not. There's no explanation why this is needed. The flag checked only by is_user(), and before thread_info is initialized, flags is zero, so is_user() would return false, right? Or am I missing something? Thanks, Alex > > Signed-off-by: Nikos Nikoleris > --- > lib/arm/asm/thread_info.h | 1 + > lib/arm/processor.c | 5 +++-- > lib/arm64/processor.c | 5 +++-- > 3 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/lib/arm/asm/thread_info.h b/lib/arm/asm/thread_info.h > index eaa7258..926c2a3 100644 > --- a/lib/arm/asm/thread_info.h > +++ b/lib/arm/asm/thread_info.h > @@ -45,6 +45,7 @@ static inline void *thread_stack_alloc(void) > } > > #define TIF_USER_MODE (1U << 0) > +#define TIF_VALID (1U << 1) > > struct thread_info { > int cpu; > diff --git a/lib/arm/processor.c b/lib/arm/processor.c > index a2d39a4..702fbc3 100644 > --- a/lib/arm/processor.c > +++ b/lib/arm/processor.c > @@ -119,7 +119,7 @@ void thread_info_init(struct thread_info *ti, unsigned int flags) > { > memset(ti, 0, sizeof(struct thread_info)); > ti->cpu = mpidr_to_cpu(get_mpidr()); > - ti->flags = flags; > + ti->flags = flags | TIF_VALID; > } > > void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr) > @@ -143,7 +143,8 @@ void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr) > > bool is_user(void) > { > - return current_thread_info()->flags & TIF_USER_MODE; > + struct thread_info *ti = current_thread_info(); > + return (ti->flags & TIF_VALID) && (ti->flags & TIF_USER_MODE); > } > > bool __mmu_enabled(void) > diff --git a/lib/arm64/processor.c b/lib/arm64/processor.c > index ef55862..231d71e 100644 > --- a/lib/arm64/processor.c > +++ b/lib/arm64/processor.c > @@ -227,7 +227,7 @@ static void __thread_info_init(struct thread_info *ti, unsigned int flags) > { > memset(ti, 0, sizeof(struct thread_info)); > ti->cpu = mpidr_to_cpu(get_mpidr()); > - ti->flags = flags; > + ti->flags = flags | TIF_VALID; > } > > void thread_info_init(struct thread_info *ti, unsigned int flags) > @@ -255,7 +255,8 @@ void start_usr(void (*func)(void *arg), void *arg, unsigned long sp_usr) > > bool is_user(void) > { > - return current_thread_info()->flags & TIF_USER_MODE; > + struct thread_info *ti = current_thread_info(); > + return (ti->flags & TIF_VALID) && (ti->flags & TIF_USER_MODE); > } > > bool __mmu_enabled(void)