Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp274557pxb; Mon, 13 Sep 2021 19:06:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEMm0P2oMRSLxKs0sWDEToy6VyxxQvF/PpbJTChZdKo6HxZygJYaqH4vtQfVBccJw8+LjP X-Received: by 2002:a17:907:2d0b:: with SMTP id gs11mr4104191ejc.151.1631585192055; Mon, 13 Sep 2021 19:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631585192; cv=none; d=google.com; s=arc-20160816; b=uC7ZcEDoDvlTxobfEmiwubHSJQvlGU4AQHGOlPY1VIkeXGdNpT37JKiZHpc85105hI c3TJWpUX/LjHSymAy/3DaD+X02f/RekjzBjN9a0R2p+iMs2ByCcMx0VHhqi7Zv4IubVH EF/S8ZNVb8z4LXt2hnQNzbi5OkDTtju2ChnCwOnEuAk3f7+uR4IdMtgOgqPyS5CeGhx3 YLL65KPPoJHF2zyRDW2gWZJoxLv0L97Ju7+8UyfdVMHkz1umWLpaSGinSgxU9Xx0BCMo Z0PgqYI2sWa7h7nIHOrSC3crCV0yQ9XXH1wygf6ww/OMwKQ5m90p/2j4I1w+/cMZ7tIN xqQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=9k08t33V+7ZlNgmFKd/wTgw8G8hwUEh+kw94pGP/OOQ=; b=InZ5eri3LYa1pvPeVggzUBU9jujU+3Fa8zrZtJEiTWBLdW37uD1J0yCKQ83IBmNRVa yP6elsrAEr2dHR3dxL5l1NTODLkFp0IprYvaP8n0aTOmaXO0bYWWQBb5O9jCXjo7DWz8 jxbgDVkmsL3+cO95KZHTPJICERXrXVUROub3g3dq9vO0Yet39Bx8rWaTbeeM+2oXNIZh l++9g1ynj0dicV7dMVikDDGcULP925ot/nIJwrp8d67OpGIcZyGLRNfmn4ZZegRV1io1 0tUPnW/F3/s90LJEbUJWsmNLYTNCCa0TOM6UmXYbfRovaEdpvDh8tUWzPh3S1y3cDdTF u9QA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx20si9494157edb.163.2021.09.13.19.06.09; Mon, 13 Sep 2021 19:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231210AbhINCGI (ORCPT + 99 others); Mon, 13 Sep 2021 22:06:08 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:57455 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbhINCGH (ORCPT ); Mon, 13 Sep 2021 22:06:07 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R951e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---0UoJi.gK_1631585087; Received: from C02XQCBJJG5H.local(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0UoJi.gK_1631585087) by smtp.aliyun-inc.com(127.0.0.1); Tue, 14 Sep 2021 10:04:48 +0800 Subject: Re: [PATCH 25/24] x86/traps: Rewrite native_load_gs_index in C code To: Andy Lutomirski , Lai Jiangshan , Linux Kernel Mailing List Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , the arch/x86 maintainers , "H. Peter Anvin" , Dave Hansen , "Peter Zijlstra (Intel)" , Dave Jiang , Ben Widawsky , "Williams, Dan J" , Arvind Sankar References: <20210831175025.27570-1-jiangshanlai@gmail.com> <20210902105052.2842-1-jiangshanlai@gmail.com> From: Lai Jiangshan Message-ID: <4ecf191a-6642-6d59-cf10-6fe51e261b28@linux.alibaba.com> Date: Tue, 14 Sep 2021 10:04:47 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/14 04:01, Andy Lutomirski wrote: > > > On Thu, Sep 2, 2021, at 3:50 AM, Lai Jiangshan wrote: >> From: Lai Jiangshan >> >> There is no constrain/limition to force native_load_gs_index() to be in >> ASM code. >> >> Signed-off-by: Lai Jiangshan > >> >> #ifdef CONFIG_X86_64 >> + >> +/* >> + * Reload gs selector with exception handling >> + * selector: new selector >> + * >> + * Is noinstr as it shouldn't be instrumented. >> + */ >> +noinstr void native_load_gs_index(unsigned int selector) >> +{ >> + unsigned long flags; >> + >> + local_irq_save(flags); > > This patch would be a bit less alarming if you moved the swapgs into asm. Emmm, this patch is not so clean and persuadable in C. I think Peter is still working on reworking the patchset and may be including improving this patch. I'm Okay if this patch is dropped. > Also, this needs a comment explaining why skipping the swapgs back to kernel gs in the exception path is correct. > I think it is all known that the exception handler in ASM_EXTABLE is running in kernel context where kernel gs is active. It does need a comment explaining why the label asm_load_gs_index_gs_change is needed, how does it help the error_entry() restores back to the kernel gs. Since the C-version error_entry() has to check asm_load_gs_index_gs_change, I think other way to handle the fault of "mov %gs" is just doing the %gs fixup in the C-version error_entry(). (see patch 11). it would be more directly, simple, and self-documented. Thank you for reviewing. >> + native_swapgs(); >> + asm volatile( >> + ".global asm_load_gs_index_gs_change \n" >> + "asm_load_gs_index_gs_change: \n" >> + "1: movl %0, %%gs \n" >> + " swapgs \n" >> + "2: \n" >> + _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_clear_gs) >> + :: "r" (selector) : "memory"); >> + alternative("", "mfence", X86_BUG_SWAPGS_FENCE); >> + local_irq_restore(flags); >> +} >> +