Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1045717iob; Fri, 13 May 2022 20:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK7ORLnCa7C4COYht7sxwUBeKZBWpyytxwKjImqXZEFklQYB560/2QDZWsBfJvKQLfTK9y X-Received: by 2002:a05:600c:1e23:b0:394:6133:a746 with SMTP id ay35-20020a05600c1e2300b003946133a746mr7028070wmb.17.1652500577730; Fri, 13 May 2022 20:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652500577; cv=none; d=google.com; s=arc-20160816; b=SdM5fCzJVJMQsAtWB5AJXlSmrZJPkxxlLqiRhzZ9sl55mPPzkE/8XKNg2M0an6130l FOaVaE4wmM4vyjYt0yhKdLHBQJ4qeyEbXtmtlv24y92ffkRnN5fUsCgTp/fl7TQ2te1K 43l2kxRwIgYEp0PF/qMVb+3l1R+D/8eltvD5sMq16rxdkfUPsMehNBvzKs1mRF6kkQWW 5lX4yuqRus11tgP4saagLxK/ZZiTGs0/sM3NcJekjwM348dG+ZdYLjxGzdf2Y5imNSy8 zjgid+/G7rYffwITv5Ie56TVov110SpCBELvLsS0UmlaaEzvr5t4oq/wD/Dr5+nAzaOV lr7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=vapj0kW4KwHiPms6GfxtxLcmGObJK471bDUmNzQRuog=; b=RdNpq0qU5tTMHMZG+dQ7Xux8K3Y5S4aTX9m3M5y2BSbdTqhNRsGAZ1SRRl49wFQjKQ MCkUJSHu+XtQIoQKe7YPuZ0xQv3S70uE/A5ua11nKr5hRy+H0ii2ckbjiriM6nruf6gK i5T7QIn4Mhe3Rc2mjlmQ+/SOC0qxf8bYa5zRLmMWDsK68oT1aDaQCmrFF4io/LTC5IgG Oaj0Eaz7Sg0WEngcB88TN9FK1OplA3R8eER4Bohh41R2jm4f+ZA81mJASUOFVGLhTfnZ XEL6LpFEI5tOwruzQC8YrRvQnGARqFI8Z69KfjJjoL/Lr1IXXz49Fhhi5rr9DlVALknX hpiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BFD5fz+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 13-20020a056000154d00b0020cfdaae70dsi879411wry.873.2022.05.13.20.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:56:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BFD5fz+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8F30A300A17; Fri, 13 May 2022 17:28:23 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345992AbiEKSBX (ORCPT + 99 others); Wed, 11 May 2022 14:01:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346027AbiEKSBR (ORCPT ); Wed, 11 May 2022 14:01:17 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F0B551E50 for ; Wed, 11 May 2022 11:01:15 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id b18so4904071lfv.9 for ; Wed, 11 May 2022 11:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vapj0kW4KwHiPms6GfxtxLcmGObJK471bDUmNzQRuog=; b=BFD5fz+C7GTIOPRH8A7H7w72GvFbrLP4mTnO1BVj2UVwNJd6mVAlOOCMUTtqhGxUt0 VxLr9shPiDClWFiSXLImqDCVH8Jko3dbCW1ioEQ7whrSgDTzpFsPGFAQgjnkC/8x3t10 DSUiXJE5fJ5eMMA78q4HZU5jhfq/qUkGnqA9DMyAHKRerVelAj1X4WHCXw5/HhbX4mLV 3lB5D0c2VpPuoPt9wqtpYe6qFT+7onxnil8dOeCdK1i54YqCN4cSR4fP0Gcg17PRIYk2 SoFB5GfleAb54SzI+XQdfvjbQ0CkD7Y70NfFk7ESmAerbbsrcDa4r/Znf43bVqgAvUtX zzAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vapj0kW4KwHiPms6GfxtxLcmGObJK471bDUmNzQRuog=; b=VVpcNlyqOGOHgD1DEr1UZxEEL8Y0pw/jymW0waum2ilrgyLGp+3XHMMWGPcnvdL9KK sT6Im0TmtI8SwmBsRupda1sWALtiNuRP/3wH3PFjmt7NA6ekQZoGwReA2oW4FkUt0RJj 7Vo1y97d7jLrJFT+EaiUdKCEnPmpati7uZy9QnXmkF6aYHe0Moot511rphS3sah/Vp66 uMyrW7oR9hgLI0417UsrbaHMLbTS2+oVHi8LonbgbEGb1h2dWahRJ/rzmAg84XIMdKvU jlu0U7Nr1Wnk8JCZBRPDSVXkI8kJmzntC9+LqgeRYOCjK5CXi0zsSLuW4ylxdsJ5DZ8H 79Hg== X-Gm-Message-State: AOAM532lueziy0Gjy5xnSGO3bD51YAADe9XmPInuTGbWNuMHVpTORT5d 6+iIsyNWqeSZwrdKldAVXdKNnFZAYmIxt57Y7+z5Fw== X-Received: by 2002:a05:6512:1291:b0:473:b522:ef58 with SMTP id u17-20020a056512129100b00473b522ef58mr20617140lfs.190.1652292073536; Wed, 11 May 2022 11:01:13 -0700 (PDT) MIME-Version: 1.0 References: <20220511072747.3960-1-jiangshanlai@gmail.com> <20220511072747.3960-2-jiangshanlai@gmail.com> In-Reply-To: <20220511072747.3960-2-jiangshanlai@gmail.com> From: Nick Desaulniers Date: Wed, 11 May 2022 11:01:02 -0700 Message-ID: Subject: Re: [PATCH 1/7] x86/entry: Introduce __entry_text for entry code written in C To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Andy Lutomirski , Thomas Gleixner , x86@kernel.org, Lai Jiangshan , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Kuppuswamy Sathyanarayanan , Joerg Roedel , "Kirill A. Shutemov" , Miguel Ojeda , Kees Cook , Nathan Chancellor , Andrew Morton , Alexei Starovoitov , Marco Elver , Hao Luo , Rasmus Villemoes Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 11, 2022 at 12:27 AM Lai Jiangshan wrote: > > From: Lai Jiangshan > > Some entry code will be implemented in C files. > Introduce __entry_text to set them in .entry.text section. > > The new __entry_text disables instrumentation like noinstr, so > __noinstr_section() is added for noinstr and the new __entry_text. > > Note, entry code can not access to %gs before the %gs base is switched > to kernel %gs base, so stack protector can not be used on the C entry > code. But __entry_text doesn't disable stack protector since some > compilers might not support function level granular attribute to > disable stack protector. It will be disabled in C file level. > > Cc: Borislav Petkov > Reviewed-by: Miguel Ojeda > Reviewed-by: Kees Cook > Suggested-by: Nick Desaulniers > Suggested-by: Peter Zijlstra > Signed-off-by: Lai Jiangshan > --- > arch/x86/include/asm/idtentry.h | 3 +++ > include/linux/compiler_types.h | 8 +++++--- > 2 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h > index 72184b0b2219..acc4c99f801c 100644 > --- a/arch/x86/include/asm/idtentry.h > +++ b/arch/x86/include/asm/idtentry.h > @@ -13,6 +13,9 @@ > > #include > > +/* Entry code written in C. */ > +#define __entry_text __noinstr_section(".entry.text") > + > /** > * DECLARE_IDTENTRY - Declare functions for simple IDT entry points > * No error code pushed by hardware > diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h > index 1c2c33ae1b37..8c7e81efe9bf 100644 > --- a/include/linux/compiler_types.h > +++ b/include/linux/compiler_types.h > @@ -225,9 +225,11 @@ struct ftrace_likely_data { > #endif > > /* Section for code which can't be instrumented at all */ > -#define noinstr \ > - noinline notrace __attribute((__section__(".noinstr.text"))) \ > - __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage > +#define __noinstr_section(section) \ > + noinline notrace __section(section) __no_profile \ > + __no_kcsan __no_sanitize_address __no_sanitize_coverage > + > +#define noinstr __noinstr_section(".noinstr.text") I haven't looked at the rest of the series, but isn't `noinstr` used in a bunch of places? Wont this commit break all those uses or at least make it break bisection? Also, my suggestion was simply not to open code __attribute__((section(""))). Does this work? ``` diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 7924f27f5c8b..10ec7039e17d 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -13,6 +13,9 @@ #include +/* Entry code written in C. Override the section used by noinstr. */ +#define __entry_text noinstr __section(".entry.text") + /** * DECLARE_IDTENTRY - Declare functions for simple IDT entry points * No error code pushed by hardware diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 1c2c33ae1b37..ce623099eb21 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -226,8 +226,8 @@ struct ftrace_likely_data { /* Section for code which can't be instrumented at all */ #define noinstr \ - noinline notrace __attribute((__section__(".noinstr.text"))) \ - __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage + noinline notrace __section(".noinstr.text") __no_kcsan \ + __no_sanitize_address __no_profile __no_sanitize_coverage #endif /* __KERNEL__ */ ``` -- Thanks, ~Nick Desaulniers