From patchwork Mon Oct 3 22:21:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997823 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C09EC43219 for ; Mon, 3 Oct 2022 22:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229916AbiJCWWC (ORCPT ); Mon, 3 Oct 2022 18:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbiJCWV6 (ORCPT ); Mon, 3 Oct 2022 18:21:58 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20719.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::719]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B47A52E70; Mon, 3 Oct 2022 15:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YNEzxy7sq+zjY4yi63fDIpq8ydIV31lv6JXsbI1TrcMa6EOFj+77pOpihJFuwZ/aW1/dY61TtRm2PSY7hO9y2X67aUVK5xbXG+q6CywIYRloJ/+Aeic3N8E2UiC59KT6Etq7By7E8amjHXMxA9knlOfbshBgFQOvDSfQS8Dj0hIBZtePlgzIwh1JJcz4IAvU/DOEq5Sb/iD0z5Zd+ZsPyAiQ1cXfFyjGfeFriUNeZEj4+0anFxiCADgLABd9vt2J6sOGH3uTbaqUV24k7To6q9h4J3ebudJfoXgTfgy1sEoOJytz3M1oLQVsORVxGpdlsb3uu80dBSxwQqxEs32OmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=X86Otev7IKDx9hRxK3rxtQT27APXJBerS/h/03ZrOs0=; b=e++yf0wwSz+zElwUT5YfD/SglcNuokwI//jKLKCXKt7Uy1w4AxmdOd8+t1pY+iRGX8iKRugWxvDgZODLQEeHjtxe6MITxHS3MUy4k2IMJ7uaeOT/AImmbliKOaM/yj1MxeREy7gDJEJkqZHbR0vwFPXONG1U/vpu3GFpHQtfy8iz0JBWUwFg8mmKvll4pPHzzAIIi6mRyK3eLnwed/miHPulVO8Z0O+dIlFDJVYj9ru4zZi8gOMcAfi/2xBEop1YAGLNPF3vl5sYR7fJwQIMlv54JKvDegIGAYyTyim4+hjeYK3MP6MR/8xgbqjnYf9+BTsj+T7PyTFpZ8Oke10PVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X86Otev7IKDx9hRxK3rxtQT27APXJBerS/h/03ZrOs0=; b=acifDe/t7CV9cSfuf/FWt9XeWFrsc+RXqlS8gFD34tpQAxOWMPnILsyt7oLxAc+vCKyr/dAByi0e+G3VhcDeLpvD+dFvViOhwWKDWb/MjMuf1jxWB+glMHHRz/YAA0YSIKTAF0VrdpeYulLnTaAJ8sM71p5TwqOj6MwCmvXTL5chVyioxZiFoBGB4i3bWyL2uX6EPY1rZJW2TmTIlIb2KoZ7Q/AXlpyxWmDMXc8xemyigQrXJEE4sF4Xth7BsCngrM5nGlTsbq3aQcLRklU5nmfBeI+T77i13cAuPfc/hbXe355eGq9rVk1INqnhCRFXGext453fbs+4z3u2vucrrw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by MN2PR03MB4928.namprd03.prod.outlook.com (2603:10b6:208:1a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Mon, 3 Oct 2022 22:21:55 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:21:55 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 01/10] kbuild: Add sections and symbols to linker script for UKL support Date: Mon, 3 Oct 2022 18:21:24 -0400 Message-Id: <20221003222133.20948-2-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|MN2PR03MB4928:EE_ X-MS-Office365-Filtering-Correlation-Id: d4a490dc-2c22-4f67-10fe-08daa58dad75 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: M1IoOnRZ8XQ77dLzJtm8QOxLQIIOErDPb/P07yoyHNVrv3XEJ3mp8TJe7LbEyz+qg9Sp7JgI6w6otVRYJF8fK26gcCoFFiNPXNfc7G0uYGKpLZNUgoc9LhLL0Nal1G7O6T/Yxj5Bb87bWSPsqnj7fLGNo62C0s+t1PK55giFBMvFcpylHKWV9FYocAvnYSwL7d50+fhNLSgYcYPR7GQgZK3oxW3aLyJHWFT93XnBPkF439qTyhrwKrp9Q5Q+00flDAX8cIq6zfGsy/zk85oJeewzwjFikrWzcvBG2EO2z6sMSNYJHbhbMI8spNydwWNU5QU3tWu+33QMVX5GOJeImEpks5OTl5lRfPVnCp74y1ujN+Hu0zthuEo8fHYZ4CG0v17/V0sGcVjBmHf+LFzD9942cmYPKb2Q9F8Vr2/miga8nC2FYlEYIdBR5PcofLdLiXMUQ6DEYUpP8F4SQwo1CgA+vRRDvUTdltUm9UxOfeAO4icxgYQx1E2D73nmq9uaZlvOJie7nQ0cJZkFIWhYw7K0DdgcaEP8BoY8JqaqLu2FDZVeAl6hmp+Gwll25jrpW0QoFsmDU8bvkkzyfAQZKe0QtcTuLLM8CHlNoKZgHAK38NvNH34RMI/K7KhRN2QUwKG8fWnhTPLsTE8S4uzTHwuo+gsDxVXOFD4zpxFLNaPMWFBr80y/RuCTidEpa9GfKw6asseNjrXl/TB2k4MHYw1i8/+wL9uZY5Q18IKibtioNQoONfYqMTAWQasATXJ7e+2TGl4CtARYNmjBs4q6qg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(8936002)(7406005)(41300700001)(6666004)(38350700002)(75432002)(66556008)(66476007)(4326008)(8676002)(1076003)(186003)(6512007)(2906002)(2616005)(66946007)(83380400001)(52116002)(6506007)(36756003)(5660300002)(7416002)(26005)(86362001)(41320700001)(6916009)(38100700002)(316002)(6486002)(478600001)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bJ9IXYJ1CYeov+FeZdjJHVboMY7rxHIY4leO37J5IZ9zaDl/yAn1OpAZSvTqVPu70snnddy2TtUvq2VeNNArUdWdqqY5HUTyYEpr26hyxYhoA/82camQOypbXt9PRiUjEQMvMDL+cVwmpZNDZc04r8pv9tlZkxc1WCKo2xsN52bBgZ1Il/lBgsmM2ryCEW/z0Uoaq2JEGXepCOD5+8GzpMOWaWMchfOj1vJ0zgJemHjoAsKH9HFVRKKwYOToe3uq5ghc3BpgRFP4PvdAVFRZNUJDXSsndVTZwIpBUPoafHypaKwDytO37kBzcKDyVsS0xZCOG9DM4G16tJiPDhxhb1C0XqBYcMW9HeDxwr3NBfjp6o9FwaXH7Y5fwKEBo5B/L2o+sCYkoR/wCLqJt3IOwvQRy7fyi40n9g8Ya62/h67Z4+LZqSrABjoxQvVzha7TQ0BqX1bfsdu7QuuNUaRF2f7SV0sR540NzzbN4gtzOxpoCpNRnPMhNRWsvgwuehgeBjCcXQlCbYSldPy2waAE7bO/O2ORy5k0vYTE5Y3sjr/NSaDcYZvRxWHL26KEwzmnQB6SLIlNldeGIvAyRMb1SZqRxrYpeJsuJfi7xFgcKsY+snq6V2o8D2TsqRKZnHqlu8GjknWjVrDiYLnnFsqxFuB7Tf5+VaO9CAgzra2NJPZfb7fMETpawJb5fhssrPBA4Xieds/dGocrFk12TRHvtOhfeFshESw/rRLQ7l175oaV36yTAQblH7NaYfL0/vPvFwOi78s9y47XYnavfVI4ILJVvSTUfr5nqjqZ46wH2oVDD+lPN/V3z/jMCaAANnPJ9qlGafOcvFDLc9tOLzNGH1fvtcQh2u7zw6uzi7ex/WRwsQ8Ah89CLcNVMierxWEgEZqivk5EX7ZLbj2c1B0DXW5fNm9PAR6GG9yheCmFIf4pevCkAqbQ2os1Xazimmqae9H/uaDWORxlNVy6Cn7ukn5YiDxyBjOSAUX+Kt1tOVuy3bPx0gGN7fKDJH0hnHQkvNQUf2N8cm/wyT1PLvgdgca5z4ziESycyZxdiF9EsHmtT1j3wUNPEw8AMcKXRcoOpoi/fOGdGNh0hlVzUuED/SS49iBz5dG2n0tcUFqoeuO5XEqTFP4t7uTM6I9TlVWHILRgntR6adYJZ7tF5P1rCnHs7mCKICwIr13BV4rumplYzgM9LIFN40eh3vOZ4Phg5R6bZgge2e1x6sTUGXXBcHDiR/X90s2iJAFhO3mLxqFIHo5PFZZj+SZKx/AQEsSaCgLmhQNd1zaNDAeBSWPZOE9dGlRRuR3RkdYAPnWjuZGFZA/PsYc8n5M/NsqreLQ9eo0thOIJh7c3egOUcZsVpGRBqOHu9edHR6zEEXCPKQdzawVn4p7OOYOMd6P5naHczlo9Tb/Zin4HjwU+KG4tltYNtzvbB7n3nXoN17Jg0aAyfe9k94RyJi1nvLDaV7mkjtnKjtiIeob7sRNax81ZWk99D6iiWlxiK/pgERHdFsm/wQ6RvjK+zkGH42bcqpd0wJ8PRMWYC6k84xz8RZEQwvB44nT2sNIEZJ2vcA6+LHVQn928lscW1+usyqp7+S9D X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: d4a490dc-2c22-4f67-10fe-08daa58dad75 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:21:54.8885 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4oMxxwibxHRrDb64aFrGlIGckWcpGmEMjFpr5G+FQ+vvc+P8z2V9y4aoxwN7m1Jy X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB4928 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In order to link a user space executable we will need access to a few section that are not normally used when linking the kernel. Add these sections when we have selected CONFIG_UNIKERNEL_LINUX. Add case to not throw warnings for COMMON symbols from application code. Make the KBUILD_VMLINUX_OBJS contain the application library when UKL is enabled. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Co-developed-by: Thomas Unger Signed-off-by: Thomas Unger Co-developed-by: Matthew Boyd Signed-off-by: Matthew Boyd Co-developed-by: Eric B Munson Signed-off-by: Eric B Munson Co-developed-by: Ali Raza Signed-off-by: Ali Raza --- Makefile | 4 ++ arch/x86/kernel/vmlinux.lds.S | 98 +++++++++++++++++++++++++++++++ include/asm-generic/sections.h | 4 ++ include/asm-generic/vmlinux.lds.h | 32 +++++++++- scripts/mod/modpost.c | 4 ++ 5 files changed, 141 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8478e13e9424..d072a52ed856 100644 --- a/Makefile +++ b/Makefile @@ -1129,6 +1129,10 @@ KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y)) endif KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y)) +ifdef CONFIG_UNIKERNEL_LINUX +KBUILD_VMLINUX_OBJS += $(CONFIG_UKL_ARCHIVE_PATH) +endif + export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds # used by scripts/Makefile.package diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 15f29053cec4..cb8b33955969 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -101,6 +101,9 @@ jiffies = jiffies_64; PHDRS { text PT_LOAD FLAGS(5); /* R_E */ +#if defined(CONFIG_UNIKERNEL_LINUX) && defined(CONFIG_UKL_TLS) + tls PT_TLS FLAGS(6); /* RW_ */ +#endif data PT_LOAD FLAGS(6); /* RW_ */ #ifdef CONFIG_X86_64 #ifdef CONFIG_SMP @@ -146,6 +149,71 @@ SECTIONS #endif } :text =0xcccc +#ifdef CONFIG_UNIKERNEL_LINUX + /* Added to preserve page alignment */ + . = ALIGN(PAGE_SIZE); + + /* */ + .rela.plt : + { + *(.rela.plt) + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } :text =0xcccc + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } :text =0xcccc + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o + *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } :text =0xcccc + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o + *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } :text =0xcccc + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } :text =0xcccc + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } :text =0xcccc +#endif + /* End of text section, which should occupy whole number of pages */ _etext = .; . = ALIGN(PAGE_SIZE); @@ -208,6 +276,29 @@ SECTIONS . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE); +#ifdef CONFIG_UNIKERNEL_LINUX +#ifdef CONFIG_UKL_TLS + /* Thread Local Storage sections */ + . = ALIGN(PAGE_SIZE); + .tdata : ALIGN(0x200000){ + __tls_data_start = .; + *(.tdata .tdata.* .gnu.linkonce.td.*) + __tls_data_end = .; + } :tls + .tbss : { + __tls_bss_start = .; + *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) + __tls_bss_end = .; + } :tls +#else + . = ALIGN(PAGE_SIZE); + __tls_data_start = .; + __tls_data_end = .; + __tls_bss_start = .; + __tls_bss_end = .; +#endif +#endif + /* Init code and data - will be freed after init */ . = ALIGN(PAGE_SIZE); .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) { @@ -380,8 +471,13 @@ SECTIONS *(BSS_MAIN) BSS_DECRYPTED . = ALIGN(PAGE_SIZE); +#ifdef CONFIG_UNIKERNEL_LINUX + } + __bss_stop = .; +#else __bss_stop = .; } +#endif /* * The memory occupied from _text to here, __end_of_kernel_reserve, is @@ -446,6 +542,7 @@ SECTIONS #endif "Unexpected GOT/PLT entries detected!") +#ifndef CONFIG_UNIKERNEL_LINUX /* * Sections that should stay zero sized, which is safer to * explicitly check instead of blindly discarding. @@ -469,6 +566,7 @@ SECTIONS *(.rela.*) *(.rela_*) } ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") +#endif } /* diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index db13bb620f52..42ebf251903c 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -35,6 +35,10 @@ extern char _text[], _stext[], _etext[]; extern char _data[], _sdata[], _edata[]; extern char __bss_start[], __bss_stop[]; +#ifdef CONFIG_UNIKERNEL_LINUX +extern char __tls_data_start[], __tls_data_end[]; +extern char __tls_bss_start[], __tls_bss_end[]; +#endif extern char __init_begin[], __init_end[]; extern char _sinittext[], _einittext[]; extern char __start_ro_after_init[], __end_ro_after_init[]; diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 7c90b1ab3e00..4b0e4f3d4c39 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -568,6 +568,24 @@ * code elimination is enabled, so these sections should be converted * to use ".." first. */ +#ifdef CONFIG_UNIKERNEL_LINUX +#define TEXT_TEXT \ + ALIGN_FUNCTION(); \ + *(.text.hot .text.hot.*) \ + *(TEXT_MAIN .text.fixup) \ + *(.stub .text.* .gnu.linkonce.t.*) \ + *(.text.unlikely .text.*_unlikely .text.unlikely.*) \ + *(.text.exit .text.exit.*) \ + *(.text.startup .text.startup.*) \ + *(.text.unknown .text.unknown.*) \ + NOINSTR_TEXT \ + *(.text..refcount) \ + *(.ref.text) \ + *(.text.asan.* .text.tsan.*) \ + TEXT_CFI_JT \ + MEM_KEEP(init.text*) \ + MEM_KEEP(exit.text*) +#else #define TEXT_TEXT \ ALIGN_FUNCTION(); \ *(.text.hot .text.hot.*) \ @@ -580,7 +598,8 @@ *(.text.asan.* .text.tsan.*) \ TEXT_CFI_JT \ MEM_KEEP(init.text*) \ - MEM_KEEP(exit.text*) \ + MEM_KEEP(exit.text*) +#endif /* sched.text is aling to function alignment to secure we have same @@ -1029,12 +1048,23 @@ /* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \ +#ifdef CONFIG_UNIKERNEL_LINUX +#define DISCARDS \ + /DISCARD/ : { \ + EXIT_DISCARDS \ + EXIT_CALL \ + COMMON_DISCARDS \ + *(.gnu.glibc-stub.*) \ + *(.gnu.warning.*) \ + } +#else #define DISCARDS \ /DISCARD/ : { \ EXIT_DISCARDS \ EXIT_CALL \ COMMON_DISCARDS \ } +#endif /** * PERCPU_INPUT - the percpu input sections diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 2c80da0220c3..a6023db6b630 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -626,6 +626,8 @@ static void handle_symbol(struct module *mod, struct elf_info *info, case SHN_COMMON: if (strstarts(symname, "__gnu_lto_")) { /* Should warn here, but modpost runs before the linker */ + } else if (strstarts(symname, "ukl_")) { + /* User code can have common symbols */ } else warn("\"%s\" [%s] is COMMON symbol\n", symname, mod->name); break; @@ -774,6 +776,8 @@ static const char *const section_white_list[] = ".fmt_slot*", /* EZchip */ ".gnu.lto*", ".discard.*", + ".gnu.warning.*", + ".gnu.glibc-stub.*", NULL }; From patchwork Mon Oct 3 22:21:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997824 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07AB2C4321E for ; Mon, 3 Oct 2022 22:22:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbiJCWWE (ORCPT ); Mon, 3 Oct 2022 18:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiJCWWA (ORCPT ); Mon, 3 Oct 2022 18:22:00 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20719.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::719]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0413F53037; Mon, 3 Oct 2022 15:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MZGZLcwrhmMFuxpdSckqK3bo1Ai9/rCChCC4EtP8PXo8hQjEvgYybAxx1xWDNKZkssFMswY87kAJaAKEOYNL5Zw5JQ2252gd3Nec2bV6XX+megjf/IQNrhwEw0ePkPUPGRckXZE4lj70dcEh25xdn+DkFHlCQJVgeRs0JpqIZPbn91x9hdwIJX2ne5jx4DfmhVWKMSumbMSz0SjQqfr0qj0GFWGrzObld7XU8swn1riCGukVPYdG31QIF6zw/rV09SKhJZjrKBhQncO8d9GdV6oYDL42S605c9x8bHGyJww72JbsLvDaRTb2NRmfzfl9+EgatArRGCh3VpvoI3ocPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J8518zTRI17HbsZNfkeZY1Q6TIPgIuAuW6ZRtNWowSI=; b=Cb9M5X3yNadbrS8qW2e1/869W2L1tz4iauBcswN3aQmKRVMoMwfYecLOg2y5tml/C9xvfEYvJ9OHjCAAbJ64nYbLN44pHlTHU+RKuyMGhbKfGT8U0cbPJXHwaadGBG0cEKIq4DB958K1epuWuanYtnEDDKE0wjplb2jOpQyaKMksbJY9BRb6gD+BgJIJ7ODO7s0r5D48zogk//CwN+/24Ipcd85dBdwOosqZiJdC9MBizeJmne1m+Kh2HsGKgLvpOSc8ArdfiSPUzZU+k+u1GbMf0CVVkDL1Oi8JK84erFLAJs1kciXIFMte/IGmzqBOn+rLDHAUbHPX4UsNXSYyWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J8518zTRI17HbsZNfkeZY1Q6TIPgIuAuW6ZRtNWowSI=; b=IGsR7XhAMdFZc0smUKWVtSp/p3/ypRtr6m7Fj7LL/9iSpMWg5own4HwQz2SNxDClPSA+EsllZUpFC+Yq7tlPpEtHoqR0q9+4hiiLh9s7/gzIxvhaviJifkjLQYWA66Dn7h53C8rCTsnTlyg7qfXOXIxNFgqwhCOLhkohZyT0VPGnZS475kKRLr/3WRZ2EhBvXufuBoNUI6vjMM2pCq1CQcpFlLoEXOPf/RP66PMnCTjyadO3WBLk0gbOLaTL4qx6BapgHd31KBa/6oFMkw7mDKB27T4/ZBVOqtCRnEmzGNhEYLKHJQqBP+h6IvI523vVeDksRGy1e5+OBOAMr+v14g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by MN2PR03MB4928.namprd03.prod.outlook.com (2603:10b6:208:1a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Mon, 3 Oct 2022 22:21:56 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:21:56 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 02/10] x86/boot: Load the PT_TLS segment for Unikernel configs Date: Mon, 3 Oct 2022 18:21:25 -0400 Message-Id: <20221003222133.20948-3-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|MN2PR03MB4928:EE_ X-MS-Office365-Filtering-Correlation-Id: a232e0bb-987e-418d-407b-08daa58dae2a X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gmQ+jE4C6SqbijVDVgWeXPjE7uLdhsVrKx2H0MvUo8ES+LKx0+2DIDiOXqmQLROvIygXWl1DrtMIYiynfZkBWImBsm+STauGdbCXC/BVUlQmigelZ0t5eZDpOiTjNURRybr/TU/0U3dLLGwSLNt96FMBG+7qWeet35x1GQTqm/85af24nK2HwzXf36rT4Ad9INugex924IfrBbZ2u037xEMUD0CoeZ3eUWzAfWPQ3VCed4ugZtgGy6O2EfUpH14RF52Tiehn0N76H2w3rFSviLFwYAZWux8KiP49A335GTa+uutT/q8icybuw0bAysOH3w+mrmvmPkjYJV4aJijfVHnTN367e55JKrZVSRZtZRF4Vuo/wkpCWVNQpntch5fPMzTa3E7MbV4dsB5Vj9M8b2G/+bCCXzmiBYbSk43SA2H847LHSFxwjJhnNOKQZvoEEjHOGwDQH8L41pPT3YxcriNwIIGDAnjkCKAEqyzSDcqXR7/PNrUj+CdC8l9k8MvrZLYiVf6qOhqNKskOZANrbEhts6IxOf4rXmqhYfFUhq3hnm6wbQu3d7CTpa6vCxapL14oSXuAdVb8JLVuBpIpoaD2E3AO/rrsLQDGJR2JL5UGVYMHBQbnOjW0PLyIDFbi70MPg34c+Hmh3t9uJqjFt2Z/1k93YNt3y3PWQYK5hgsE3MHrk2bV5/SjVtXEHRAbFQeVsH/qM2RvAeeODVzmod/cqn5Fg+R4d12cfFz7pPi/RyXsJulP7zVJYZpxLNHiS0QaLgpx1H8epMu/qyPSJA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(8936002)(7406005)(41300700001)(6666004)(38350700002)(75432002)(66556008)(66476007)(4326008)(8676002)(1076003)(186003)(6512007)(2906002)(2616005)(66946007)(52116002)(6506007)(36756003)(5660300002)(7416002)(26005)(86362001)(41320700001)(6916009)(38100700002)(316002)(6486002)(478600001)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YuYwJLoeVeZXSZUmCeV2JJZZmQkzv+aOOe95Tf+3AEoGIDRys2pbh47l7R23r+0/RGt6vRxze6XA5bw0nxd8f5B0HIe8VZUNEn1QJvAE1ZxzcfyVSqP6d+7ZPIkhMMxOt6sxh3egnCjhJVQImgL8LsDWrIz2TMSM89wCZXEydG83oXhA93wYh1/z2y6A1Za2BxdXXKUsIC6f2NG4PAU0lnFLWmPXqfHlKlndwSGFmwmLGXrfFL4asFNBR7BtsZKjKt48uqJcue1gtVdyRXhSgRiNcg0BAZvukz8i9nmzHMDWHogUR5olwTKBFFxy6u5t/aRa58Y8gdB6kiD/mvSr/TkyOlUGdIHi1sD/gGaSLD0aQvCYcIT5MlhvIE2M+ludu348w3scD85LaW/faG32kFbBSiQCCd6jJdGXY+kek+CRpzRI1QUTCK3Ck3OvQ47AOLAp+Caz0P/Wa+nNYST5SK3zMAV4y3D9NFMnsgeHXTiKLmOb+btFc4eIayZMBiAGLMONIur2YeeQ6pQDHi9lhkEqb/eadTLJcwtgU97VuMH4ZGAHeiXRXROuIMzOlHvhDqQxnJQuPEsXw1ucJ/81IOoPrf6XpvRsuaBC9TivhRqM4wBdO72Ya8jJavcLQCU0Z8zst26f8YuVRKs0Dp3PqR007J9NWBMwIO6v1bsm5EQhdtn74XzqPs2GgJK+Y4lnfupo189Ek7xUodDVFmGwBAFX5XWhoY1mfaxDathNDvIvQ21SucPEt4/42mg+r6adtEPKaenW2k0ZRe6WJcNejI8DNGEu+jNa8E6oBMV5f48SK9OEhSZd2RaUTLsumFlBHcFyhF6gUMNHBLtN6Db74V4oLEvPILB1pCGI6bhezUiiMPRzlqP8f97Qu1kohK3RCiiJ4Weh5YzSXAK6Zip7dfNmI7zs9Yq0eM3bYWXCWN0jRoxUibe1WUyXgsD8UyDTbjXCHlmyp7eFHaCw916jDuOb3zK9y4g/UTnBAT0+f9VhxA99XLNtVQ5qL/mCt7qGhSBoNHQgxb0LTdkD17FIBveoL3FrvRS++adY8IxxoW22UozP5I60EGuvXLYmaChbnohhMloCnbHE5au9lShgpOIc4OV+pT3jbE2K603QLVW/isynWHjUz5s+DBPVrcVqqoS916pXr1/qMxxIDp9kVT5iMcwWjm3SH1dMu0A1gF9k8Ew5gUT447d7O4SwYLRn4BIUsVt/y7+gRfXebQHB5xJnEuUzhDY1GGTV0JF57jsA8pjNHwej+kX1/sSxaUEp/a2nEahxgVnycGkV9rd0PrXr27mjtqiUHYm3a6z+zh35omsbNeGhwaqKavZ3xaJpWnzkx29UBGAx+8iLp9Gn9vDti7CObKewrc87OhQ0GRNqT1cTa0lgh296YH7l0zTKTRCXfkPDCpZIiJaWwRam+X8zmESNTuaLKnYSKKpwTL3EPxhTFuvlvMDsbK6wcsJF4yYLFRVfk1TfnI96+idTss5Pavf/t8jaiK0T1ST5ea87KHyL64E4MLNQaIcMUdvWaYQeyIB28wKOR2SLrzTRlfOnb4z/g1mXJeFwiLvn6yBUam+5RX2Yl/NX24ixj7ty X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: a232e0bb-987e-418d-407b-08daa58dae2a X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:21:55.9666 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rwNLJFU7uVriXvc3j20WELWE0GjNjOITOd7J6aZPS/8+5rMtWFTtT83HhTSaB2ic X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB4928 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The kernel normally skips loading this segment as it is not inlcuded in standard builds. However, when linked with an application in the Unikernel configuration the segment will be present. Load PT_TLS when configured as a unikernel. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Signed-off-by: Ali Raza --- arch/x86/boot/compressed/misc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index cf690d8712f4..0d07b5661c9c 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -310,6 +310,9 @@ static void parse_elf(void *output) phdr = &phdrs[i]; switch (phdr->p_type) { +#ifdef CONFIG_UNIKERNEL_LINUX + case PT_TLS: +#endif case PT_LOAD: #ifdef CONFIG_X86_64 if ((phdr->p_align % 0x200000) != 0) From patchwork Mon Oct 3 22:21:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997825 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20B99C38A2B for ; Mon, 3 Oct 2022 22:22:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbiJCWWG (ORCPT ); Mon, 3 Oct 2022 18:22:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbiJCWWA (ORCPT ); Mon, 3 Oct 2022 18:22:00 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20719.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::719]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D95B452E70; Mon, 3 Oct 2022 15:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mEE53YJ5kYmxd8rsjV6ZkpKLi/EyQVjAlODnvvehz1n5Px5BCDrIpAK/ohIFrUKFyI6x6axzJ8b0tq7fnBY25WtVNccJyI02+6cpI8B/H+BtVKEoxcgMUPBaJmWyfXROLGZ8AZn9itTkzO4u3tREcxy/LD2g3E9a8/HwgO8nVCa1D9KvnLWyfo6QZEsbmKQqqkpa9bz3DuRH0Mc66HVmnSGkGPbxj2H52dmgKGtcGrtFweBN5KSrl+dFlEeFG88hXmw9g4dqNLO6l4rJ1TIzEZtPKuFzdbdAXy7CAty+MDHSEPkaZwlAvUzKWMYe9h/ZxiwLolwxGUxGhYJ173G4IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lZTIAXW3PIYT2vnKgz/NB6QKRzbYwk7TXNTYR7IO2XI=; b=E2CEEQQc/EreV/q+mwSKwcDL43tp787xFZL0THkeSu/F+qBnv5SX3Fhm8WsOrohgHSVBlhCgeISvgzNjNffj9H6OuYvIaucL25pnvC4L8pA8chrq83x36tcKqhdZKIlauz8PBwJeRDewuC3Ede9NMi254HLUuFQm/UDSepHoHPdBz4oo5j/LCS/AxDqbhXOBX4JjwHGswUZ/C7I7sD1kBrLknFxBXtqJIOEMb36pUWrVbUuuWuZ/AhiLdyS9zvPjlydT5Hgji4ShZNMg+qbwqoJnaOs0rQajYyBDK5wR24WPLOBteePA0NOzXzGxk5NJeBD6IdJ7h3GLrAnRTEk11A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lZTIAXW3PIYT2vnKgz/NB6QKRzbYwk7TXNTYR7IO2XI=; b=sNFDzkgxRGYu/Ac/deVfqkjVVAvj9EMO7hsGbREtAm2VexlzUHxe4d3jZd6Ue/39wN+mfCaV3NQNk9aELVqPIC3cd31oPhIYPWC1ZZUAefIeuROAV3Pz8Wjtor5fTEaa+kNeCkqsufS6VG68AvXbwix3S0aOMaG6P2DJzcQ0r+4T4xB7GejUKd7lRHySImSw9ZZAHLF/pCovtplgFn7nXM41PKTHTsC8+5CFNGvtiju/5kXL4tAqIB4dMYd6oCBto3Lc02Eb4AixeJgiTNaypqyT6agmS2PQPWX1LUMiV/ZJsh82LQvoPzv87E3SDuseNAslWMj4hpbOXDwQ84ZBZQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by MN2PR03MB4928.namprd03.prod.outlook.com (2603:10b6:208:1a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Mon, 3 Oct 2022 22:21:57 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:21:57 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza , Daniel Bristot de Oliveira Subject: [RFC UKL 03/10] sched: Add task_struct tracking of kernel or application execution Date: Mon, 3 Oct 2022 18:21:26 -0400 Message-Id: <20221003222133.20948-4-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|MN2PR03MB4928:EE_ X-MS-Office365-Filtering-Correlation-Id: 24145433-6598-43c4-d244-08daa58daee1 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tOOEsiurEVHVZPTgyLZHoiALIhwmwQ/3hcPPn/BBLpsFkqCP+lp4XS9yLCwLyFSBx1k/eOKnaqwoaeKBPGLilSG34EZ59ioJRRP/H+Vmj9VDnX+D936CVI17gd+L7xKT2Nu3kFg+no5sQoJV11m3B6duceVWyklNo+XfHpmcgevqgFs+gxl9BlCJG1Jy45kLANWqEZykc/OlWcmbHcS8wFLWdlFysxQGMzbYbXfv0wO0V0RA6rKnFbg+1CQn1rmH1kgsPZQefDcvkiUjmRpAy2CKmUxWsO5sWj6cC8/U+gSOTM6R9qIiEstYyaCmjiTNGgIFyzyTO+YFuNL6E09adqoiSKoV1dXbLENRYGQlPNdbwl33dOyZ6S3KfojdzeijCUjokkU0wjVywpwR1oSMhE01QChkTeHyAAdwUAihji9jv45/V6F3hEIoRJoodJTmCo37CawIUmuQpSgonqrHEjGVClMqwMSyV8MMAnPki+P9b5DWBx+iESYyi2iPGEoSNCGsr3kUKTzUyrACNmzy/5dXJZj+cXnVE+slkI2mFSrQpeCACSFL5MKGlieTmEzl2rwMblCP2seAKeurd8IW86b+cT8BVhe7wAsq0zzAYjF63LgToZVHwOCzwJOOOx4pwClWSGJItyFFLkCmYYJEupKlP0W2+k/nC2msMYiSp1/WkWS7UqHuE0+VWxcm1lBCBlobFBEyDemP8SLc50nH6biwP4kq5wqOVaNTGOfO3EM4rNW9Z687f2FWmPJrdssEO+sy3u/S5tUtreAyJqXpyA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(8936002)(7406005)(41300700001)(6666004)(38350700002)(75432002)(66556008)(66476007)(4326008)(8676002)(1076003)(186003)(6512007)(2906002)(2616005)(66946007)(52116002)(6506007)(36756003)(5660300002)(7416002)(26005)(86362001)(41320700001)(6916009)(54906003)(38100700002)(316002)(6486002)(478600001)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tpN28o5aaoXqE4QPVDjmZQvWwEwRt/hl6t6pe5o4Av9Pe8nIS/ivtFHMeGTywLL2TR5uc54wu2f6dlzi8Cdp+3bamXXwixJAjUTnJgtx25aj0ewisrAeYSCofFf0CSn1bDWlfJP9B3kAqhYNTYBKBN0Bp4XwFgrRRFh+Fz4k0nsn7VjmGezLEiyf6g1U5Nl8kyvqyWpxIGr5uMZ8G0H8ata5sdpga833dnr+Tx2C6mKET59euTuKR5Wgk4Qd/KaumJ0j5IdGiSkWZgp0fNLkJ/YLOsLadCG+0NoqBpZQrg8/MQjw7eNc7JQs6XgITlN0quDKJixGYcmCWYTESNY5yeRPX7GUWiJLLxc/wwK8NsC0DdHMZRl6gfpml+QbkhN06AcONV5IKa+5tM0JO2jplQ4FCfTTaLohLmyVZ9yTXkiQwlgpJc4HHb3tydtGm89MxOlhlBowzrFwCHg/rZiRBKb4JfBz6OoDlVFi0k8tSUse0hP6RmimC0gfAL1RW0p4LiJQTMu5okvS0EV5f6+5U6SeN8LjwX76E/qIOb4nDsCUi4sQTSQ3dLMEGlwAn1O9PpN3X5lISPXnuMY7Itm/3ZllWo/ntjb07Iwu7f3dJ138aEoRLgRuErHAvlWjC2HJU1cB370mj9UokoOKK5U6CQE7WSD1jy1EnqR2Cuih/1leJ1WNrxeJIjAMIHJkWxsXCWEDiQ6ZmUX6sRmn+fP4uCaBeb8Ln7fyyLfhhKmbUcPIBN4HPuMvaEhHhXBeZczw3/4aGPuYXbW4j5mpb1Mq0LR+g0QI72iyx6p95X0yksQfqGR6VkT/88agGjz6rMmP2Lqsan4A/WMBekIJmEcEb/marQJCItskROtfJNBm22DfDGQ6XQLmJ9MltcHflw5jEZWMit/lgNIC3rzqCDdFXb3qcHiAl/I2C1AC7f5s2T3Q7/Fzgl/2BtFtjpUmhvuFz9Zi4Ke28bW/8BkyvDSaxTDenQ4g6TqQ2JSeSdb4rKRMU1QKx8I3bse4J6gK6t7NRcWX3D721SW/COrCVw/MIZi2fSsjbtGTjHe4BF5b84Hg25jdMTXQ8/LfyzLpAiIRqFlxlnu/wfaxiWy0YZLuPPfO9veLgGBUQBRqcKZFB9xotr0Jticaz1fEh/xTM7NPAqPYmOY4oCHmGR463Ch0yrgzKMbg5FZFtm0jtC/5o7la1inHavonBOpewjZXgPRkpObTBQVGbSZe/no/Po68jMHUo7HPI0WyvUI6rNnCJU4mBgHCW9p7CLJ8rcNlOuVLvKE6zofubWACyWNUf6i/ke15QsTA+4bXypMbt/hZdnnsOoUoEPPFhg00ALgjZDK6NJwy2kQKIehDguZSJqyfyffieV5XsMZZ2TmXM3IbrPSZzy7vS/SJa+BC7V38BLdHvMAxNxiDVk7n3KIXglR/hVfpSwiKnBDJ1SCrBHzmQEK/ERrTru07tg5j+uw6HkjMFH4YGTFXp7Cg+vzRAChGcOgQCnMNgb/JAoK3swfGYZFgWmAKopeMRxVVaDtV/e6PC3unq8zSIdFSMqF7EilZtAwu+NIoxnBAh4NJQDswI3Pip0UYn4pTx1bwnv75rI+C X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 24145433-6598-43c4-d244-08daa58daee1 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:21:57.2790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ff8u7t47tT+cHI7Uzv+saWmkINimrz8m7lftvladVsrm0ZjzohA4Q8XwHGFVOBoF X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB4928 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Because UKL removes the barrier between kernel and user space, we need to track if we are executing application code or kernel code to ensure that we take the appropriate actions on transitions. When we transition to kernel code, we need to handle RCU and on the way to user code we need to check if scheduling needs to happen, etc. We cannot use the CS value from the stack because it will always be set to the kernel value. These functions will be used in a later change to entry_64.S to identify the execution context for the current thread. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Co-developed-by: Daniel Bristot de Oliveira Signed-off-by: Daniel Bristot de Oliveira Co-developed-by: Ali Raza Signed-off-by: Ali Raza --- arch/x86/kernel/process_64.c | 22 ++++++++++++++++++++++ include/linux/sched.h | 26 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 1962008fe743..e9e4a2946452 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -501,6 +501,28 @@ void x86_gsbase_write_task(struct task_struct *task, unsigned long gsbase) task->thread.gsbase = gsbase; } +#ifdef CONFIG_UNIKERNEL_LINUX +/* + * 0 = Non UKL thread + * 1 = UKL thread - in kernel code + * 2 = UKL thread - in application code + */ +int is_ukl_thread(void) +{ + return current->ukl_thread; +} + +void enter_ukl_user(void) +{ + current->ukl_thread = UKL_APPLICATION; +} + +void enter_ukl_kernel(void) +{ + current->ukl_thread = UKL_KERNEL; +} +#endif + static void start_thread_common(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp, diff --git a/include/linux/sched.h b/include/linux/sched.h index e7b2f8a5c711..b8bf50ae0fda 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -746,6 +746,13 @@ struct task_struct { randomized_struct_fields_start void *stack; +#ifdef CONFIG_UNIKERNEL_LINUX + /* + * Indicator used for threads in a UKL application, 0 means non-UKL thread, 1 is UKL thread + * in kernel text, 2 is UKL thread in application text + */ + int ukl_thread; +#endif refcount_t usage; /* Per task flags (PF_*), defined further below: */ unsigned int flags; @@ -1529,6 +1536,25 @@ struct task_struct { */ }; +/* + * 0 = Non UKL thread + * 1 = UKL thread - in kernel code + * 2 = UKL thread - in application code + */ +#define NON_UKL_THREAD 0 +#define UKL_KERNEL 1 +#define UKL_APPLICATION 2 + +#ifdef CONFIG_UNIKERNEL_LINUX +int is_ukl_thread(void); +void enter_ukl_user(void); +void enter_ukl_kernel(void); +#else +static inline int is_ukl_thread(void) { return NON_UKL_THREAD; } +static inline void enter_ukl_user(void) {} +static inline void enter_ukl_kernel(void) {} +#endif + static inline struct pid *task_pid(struct task_struct *task) { return task->thread_pid; From patchwork Mon Oct 3 22:21:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997826 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F19AC43219 for ; Mon, 3 Oct 2022 22:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbiJCWWH (ORCPT ); Mon, 3 Oct 2022 18:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbiJCWWC (ORCPT ); Mon, 3 Oct 2022 18:22:02 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20719.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::719]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D348E54674; Mon, 3 Oct 2022 15:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fI26nPRZa/d3jU2XAkHP6eL0Eb6B3qsa/f8suWH7PK7LyGdUUwKt3VeZs70uS8QkXdh/GKAgI6g54l1uxYoVdoVOvpoPbGd2xP6prlYdhC9OjxciXXGrw3WvVlTLsrdjR40D4/WI8tCYQxRVeTmUPh3XaOm+Bmrol3VaKD/ogrTBXDHLuA1a2sgzmQKy+lng/aNuKPC19kp9SiYGpnaFDlGmxXoo3/MAqkzO+7EGZ96/wjes0wWdvEtRJn0u71GO9m8u5uPiuFOIX0Zzcr3C1469h5+5FmFT8GN6aXrbzAEN/aKm8FVaOX5/ov9lj6ZJPX1VaedKNunaHo5zlbGttg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1+rPTf0CItss3USZRkJE/pNW3KYQAdNHkWJKYHQskio=; b=ed+6rKrmZL3m33FyIyBGTyll8WCUw9+8A8aW1BrzVof+0GFR8kmWJj18mDYP7F/kt8sbMTzDwgmI1POYI6gIRxdTBqTXfcgWO9Gu6TwfrgzHeLnlvOvcVbExNN8G/6YcBoCq6y/lOn7YYhnFri1vlgDmul4fhw81+mr5yOdnduGmpRyX5uqrS8b/tQoV1orIt2QCR5lUnj3HKToLsVwyONOGELWM+oNnMYJMd42gjSn/lxRf0yS6QNI5cil08tT5tordimD7hcUaoLEv0lphuhAHTVkLfLlGbjlu8rZEBf0AzMTkB9zw6asQHuiV6h9HW9wgq2tvgV2zVHkH5bj9TQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1+rPTf0CItss3USZRkJE/pNW3KYQAdNHkWJKYHQskio=; b=FLXqIeMYrzo7gI5FBlloW2EC2CUnCxlaayYD78ar0xZftu605m5oOBuPkExMN7y3YI8WIls2oYz5svBXM+GIQ0zZdBCGyzRVg003lHVn95EJSlEraJ3gbF6iW/MH9fKGepnkE3a3Iaztf8V+cMZAxb6e19ZYcp/6RON2NwNT5VYSu1Kgk1BGyKF9uYF4zY4aS8iJP235r5WetwfESSd8q8w3PM+H1fQF42ZrCx6ijaGRnz5kQmHV8VQuMi/ey4uTaRyc9UjsCGFZQvuzNSAEuqcPjnKGgtJH0jcGSu8ERZHxg7QFSzuh2hQ7rhwuuvAlsE+w8y0NvVL7pRPvCwAVBQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by MN2PR03MB4928.namprd03.prod.outlook.com (2603:10b6:208:1a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Mon, 3 Oct 2022 22:21:59 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:21:59 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza , Daniel Bristot de Oliveira Subject: [RFC UKL 04/10] x86/entry: Create alternate entry path for system calls Date: Mon, 3 Oct 2022 18:21:27 -0400 Message-Id: <20221003222133.20948-5-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|MN2PR03MB4928:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b01462e-0159-4720-c26e-08daa58dafd9 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yP+sKtyomkkUI7wByv+vozQS7Ex71VwmqPvYY5Kf1K29k25ZQuZuiBQjZykPtFF6NIAPIdgWzCLg+t0L3tHWaMcfloxAZ9yyTTNmziPn4GOCIsude84MmoecUzWveN+7GJZFqstO8s8asJr6YwaFkEZ6LvSrDCQbWMsWgWbTAFpIExNEfcRXS3Jp8QvcUt4PT6hjeq4HOFueyleWkAfxV5OQmofaACLrIVQVUFS9aG3/tGMbktM7TGg5xRVfOCsudPFoTplbcitmJhwcYbh82ZOI6N3ejThq7BVuys+Ot4jvPV4pwYGKvPd9E9fVtYjt+odnQeVMRenqkcFtKypOhgMl178GL1v94GhxkOTJCrLdUkZJdAeXNBjoNMuUSrs+yRId3Llm1YK2NUYKnZhveTb209+fAznq8s+FaYo8VY5Q0UgKlHptgxR6rIsdLLGaQDCzcbdTIaoqpD1sBaEz2uKmLXk8pO6g/CIouwbcs9PkJF0cCvB0vgpt9tTPPH57I77zyAVkBrcCEfJriqS0tW6td466X2YzMrg1/MUOQ465al0ABNY02yMGTk/weoJBy4Tg2RHV9uJzkBPPB4ut3nZlXw1r2qyFB4fpex08WiBc76kTUt61XWgdqLNJ1XPJEAbZptiQy6xoLUNHE485vBr4tWanz/UBeTw3l4Bu+d/DQpic1U/ezNESFDJUq19FAiuh/C77EGprMw+mDZcFw/uL8q+VMK52b6uDlTbP0lPZsC8BduA4ruoEVcJiaT2tVxveJNTVeTQ7iUK9SvadIQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(8936002)(7406005)(41300700001)(6666004)(38350700002)(75432002)(66556008)(66476007)(4326008)(8676002)(1076003)(186003)(6512007)(2906002)(2616005)(66946007)(83380400001)(52116002)(6506007)(36756003)(5660300002)(7416002)(26005)(86362001)(41320700001)(6916009)(54906003)(38100700002)(316002)(6486002)(478600001)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AvGYzfed5SZaETLXeWXSfsOMR7Hk3njLFxd60WeLCymuBqZu9KAr2ocA9/l3p6dVEg+WzlfLThXq68WMcoxUInIRYQU2PsIRE8+1YZBdO0CmgoVBKLIuXjSGjW/L5RJBLBBFEhCRWA1k0UoT+mrYFFUtGOcrwOg/5uBkViYiiPobnXEIyY/w1ULQxVH+er3NMwjqtoH02GHiPSCe9z9KZ2RBV6zzWOcRN+/3j342mEUP65qoMvXPJ3ENMLkLXVh0lONsYv53s/7nTIxNV2pJ+zueAEBcDX8RdBdQsXESVUBhxUuF9C0NC7Mg3yInSHZQrunhpHuMvdmyIQjLlE/k/dhTSN+Oxv0iDtPxOpMEVgvm0OXCn5qzcc9SxLD9EkssNgSyA+4b6PFUpYNaVQkRakmSpPJLBv7Powk5GA10ouaZdK+9OdyBJfIJx/qm9Ncjw7y7NU1IOsA0tfljiY/QrsdKn/VcA7NkmSwrfjHGFx5fgbiG0PNUUCHyWAvfisT4ASexP8RICdWwEVbmECQ5nUodWxWHFM8kz3GOHVEmjPml+uzSNlDMTTIQhcZVflhyatFqvzVTF6ofXE1m2/C+VcbCW3NjZKSmheV6Rwj3kIEyzimWP1HZZBR6yFf8d7jQ5ZNUx+XzMfge8UZt+pdcXrIbaGLqT7mQeqjI1dP8Vxqz8uAXGTK2I31jhAHIvM3DI/qEO4U/bP/YVsCQ98XkJVt/1YNf+wLcaPN1paiaId3+ZwOC8U4UCLIdszF0aMqIDBG29af8HnkOx8wDKT0aUcO3wm2XV0Xh0ndJ9OTne0WC+ExBH12ONCpUCxzyKxPuO+mjeXYFw15+YYMeJoyJBcDrdlPvzYH3sLG/ubRn81ztXZSckc5IJsz81uqi5JsSbVXUUpHBmfz/+5mHaa1dXpVLbokXft4SRcrVuRusGx1dHoPwBNQs9VRTTS6Xoyb2Rw7bwuFpiZP+81eoYRTzT9+lrxidzU0OHh7LT3ez4fY0L/mSq8IgZhcRjUVuEUJiVQYt+yp3pr8MYjpE2HEOCIFKVo133WACNbDnzrYrY9JCaaKLMNr5XJRFBvOvpVpAhyX/rB9l3MNaAS7+nlGWIMiZrmrSjLKZqmwTAVmBvef6Zp4smm2+NrIMiK67wqM/SqoEe8FXnefRxEH8P0eJftVin1VRN65Y5wMYv4gtKTPpMyXrTmLJAzhHyDIzXWLmSA3+qDSOz6oZQn7alzf1ERkl/p2qUvozzatd35/2IYxaU1+nRNWZO13oeI/Wm62cMc7Bpf9UU8lU3A7CS5rXLP0Uct6gRq1UV8CY55N4NqvgdCLFrqYwZobgJaXKt7UgcpmM/U7EWJETyylIgRWOHTUM6h9ODwBMMVp4oAvbyqwXblx98yaTSssIF2bXRDcuT4b/Xr5ZmtPum+wjoHP2Ng7PePkqaAhrTyH0cGL/GtX7xr1X7OYySv/ozTmg7/rXOGVEGN1qm/rErrnmKAuiigAv9kA5t7hVDRJ0JqL7A+C9VjGhly8KZComyuCJXIMN1sF5YyJK9woFUjg8jUiMQTpdYlKw2jCajjMSjNPufpYzTX0g7P055jw4LUqRo/79 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 6b01462e-0159-4720-c26e-08daa58dafd9 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:21:58.9195 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2cuD0F6EJHCz2hjRD0siivoKTlpYeVFB6mn3q/sCkmVhvU6bdua42fZZUF/cS/wp X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB4928 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If a UKL application makes a system call, it won't go through with the syscall assembly instruction. Instead, the application will use the call instruction to go to the kernel entry point. Instead of adding checks to the normal entry_SYSCALL_64 to see if we came here from a UKL task or a normal application task, we create a totally new entry point called ukl_entry_SYSCALL_64. This allows the normal entry point to be unchanged and simplifies the UKL specific code as well. ukl_entry_SYSCALL_64 is similar to entry_SYSCALL_64 except that it has to populate %rcx with return address manually (syscall instruction does that automatically for normal application tasks). This allows the pt_regs to be correct. Also, we have to push the flags onto the user stack, because on the return path, we first switch to user stack, then pop the flags and then return. Popping the flags would restart interrupts, so we dont want to be stuck on kernel stack when an interrupt hits. All this can be done with an iret instruction, but call/iret pair performans way slower than a call/ret pair. Also, on the entry path, we make sure the context flag i.e., in_user is set to 1 to indicate we are now in kernel context so any new interrupts dont have to go through kernel entry code again. This is normally done with the CS value on stack, but in UKL case that will always be a kernel value. On the way back, the in_user is switched back to 2 to indicate that now application context is being entered. All non-UKL tasks have the in_user value set to 0. The UKL application uses a slightly different value for CS, instead of 0x33, we use 0xC3. As most of the tests compare only the least significant nibble, they behave as expected. The C value in the second nibble allows us to distinguish between user space and UKL application code. Rest of the code makes sure the above mentioned in_user context tracking is done for all entry and exit cases i.e., for interrupts, exceptions etc. If its a UKL task, if in_user value is 2, we treat it as an application task, and if it is 1, we treat it as coming from kernel context. We skip these checks if in_user is 0. swapgs_restore_regs_and_return_to_usermode changes also make sure that in_user is correct and then we iret back. Double fault handling is special case. Normally, if a user stack suffers a page fault, hardware switches to a kernel stack and pushes a frame onto the kernel stack. This switch only happens if the execution was in user privilege level when the page fault occurred. For UKL, execution is always in kernel level, so when the user stack suffers a page fault, no switch to a pinned kernel stack happens, and hardware tries to push state on the already faulting user stack. This generates a double fault. So we handle this case in the double fault handler by assuming any double fault is actually a user stack page fault. This can also be fixed by making all page faults go through a pinned stack using the IST mechanism. We have tried and tested that, but in the interest of touching as little code as possible, we chose this option instead. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Co-developed-by: Daniel Bristot de Oliveira Signed-off-by: Daniel Bristot de Oliveira Co-developed-by: Thomas Unger Signed-off-by: Thomas Unger Co-developed-by: Ali Raza Signed-off-by: Ali Raza --- arch/x86/entry/entry_64.S | 133 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 9953d966d124..0194f43bc58e 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -229,6 +229,80 @@ SYM_INNER_LABEL(entry_SYSRETQ_end, SYM_L_GLOBAL) int3 SYM_CODE_END(entry_SYSCALL_64) +#ifdef CONFIG_UNIKERNEL_LINUX +SYM_CODE_START(ukl_entry_SYSCALL_64) + /* + * syscalls will always come from user code so we dont need to + * check stack cs value. We will leave that as 0x10, because + * kernel entry and exit code will always run on syscall path, + * no need to check cs on stack + */ + UNWIND_HINT_EMPTY + + pushq %rax + call enter_ukl_kernel + popq %rax + + /* tss.sp2 is scratch space. */ + movq %rsp, PER_CPU_VAR(cpu_tss_rw + TSS_sp2) + SWITCH_TO_KERNEL_CR3 scratch_reg=%rsp + movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp + + /* Construct struct pt_regs on stack */ + pushq $__KERNEL_DS /* pt_regs->ss */ + pushq PER_CPU_VAR(cpu_tss_rw + TSS_sp2) /* pt_regs->sp */ + /* + * pushfq has correct flags because all instructions before it + * don't touch the flags + */ + pushfq /* pt_regs->flags */ + pushq $__KERNEL_CS /* pt_regs->cs */ + pushq %rcx /* pt_regs->ip */ + + pushq %rax /* pt_regs->orig_ax */ + + PUSH_AND_CLEAR_REGS rax=$-ENOSYS + + /* + * Fixing up user rip because rcx contains garbage. That's + * because we didn't come here through a syscall instruction, + * we used call + */ + movq RSP(%rsp), %rdi + movq (%rdi), %rsi + movq %rsi, RIP(%rsp) + subq $8, %rdi + movq EFLAGS(%rsp), %rsi /* EFLAGS in rsi */ + movq %rsi, (%rdi) + movq %rdi, RSP(%rsp) + + /* IRQs are off. */ + movq %rsp, %rdi + /* + * Sign extend the lower 32bit as syscall numbers are treated + * as int + */ + movslq %eax, %rsi + call do_syscall_64 /* returns with IRQs disabled */ + + POP_REGS + /* + * The stack is now user orig_ax, RIP, CS, EFLAGS, RSP, SS. + * Save old stack pointer and switch to trampoline stack. + */ + addq $8, %rsp + + pushq %rax + call enter_ukl_user + popq %rax + + /* Swing to user stack and pop flags */ + movq 0x18(%rsp), %rsp + popfq + retq +SYM_CODE_END(ukl_entry_SYSCALL_64) +#endif + /* * %rdi: prev task * %rsi: next task @@ -465,6 +539,14 @@ SYM_CODE_START(\asmsym) testb $3, CS-ORIG_RAX(%rsp) jnz .Lfrom_usermode_switch_stack_\@ +#ifdef CONFIG_UNIKERNEL_LINUX + pushq %rax /* save RAX so its not overwritten on return */ + call is_ukl_thread /* Check our execution context */ + cmpq $2, %rax + popq %rax + je .Lfrom_usermode_switch_stack_\@ +#endif + /* paranoid_entry returns GS information for paranoid_exit in EBX. */ call paranoid_entry @@ -520,6 +602,14 @@ SYM_CODE_START(\asmsym) testb $3, CS-ORIG_RAX(%rsp) jnz .Lfrom_usermode_switch_stack_\@ +#ifdef CONFIG_UNIKERNEL_LINUX + pushq %rax /* save RAX so its not overwritten on return */ + call is_ukl_thread /* Check execution context */ + cmpq $2, %rax + popq %rax + je .Lfrom_usermode_switch_stack_\@ +#endif + /* * paranoid_entry returns SWAPGS flag for paranoid_exit in EBX. * EBX == 0 -> SWAPGS, EBX == 1 -> no SWAPGS @@ -577,6 +667,11 @@ SYM_CODE_START(\asmsym) ASM_CLAC cld +#ifdef CONFIG_UNIKERNEL_LINUX + movq $0x2, (%rsp) + jmp asm_exc_page_fault +#endif + /* paranoid_entry returns GS information for paranoid_exit in EBX. */ call paranoid_entry UNWIND_HINT_REGS @@ -655,6 +750,19 @@ SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL) /* Restore RDI. */ popq %rdi + +#ifdef CONFIG_UNIKERNEL_LINUX + cmpq $0x33, 8(%rsp) + je 1f + + pushq %rax + call enter_ukl_user + popq %rax + + jmp .Lnative_iret +1: +#endif + swapgs jmp .Lnative_iret @@ -1044,15 +1152,34 @@ SYM_CODE_START_LOCAL(error_entry) PUSH_AND_CLEAR_REGS save_ret=1 ENCODE_FRAME_POINTER 8 +#ifdef CONFIG_UNIKERNEL_LINUX + testb $3, CS+8(%rsp) + jnz 1f /* user threads */ + + pushq %rax + call is_ukl_thread + cmpq $2, %rax + popq %rax + jb .Lerror_kernelspace + + movq $0xC3, CS+8(%rsp) + pushq %rax + call enter_ukl_kernel + popq %rax + jmp 2f +#else testb $3, CS+8(%rsp) jz .Lerror_kernelspace +#endif /* * We entered from user mode or we're pretending to have entered * from user mode due to an IRET fault. */ +1: swapgs FENCE_SWAPGS_USER_ENTRY +2: /* We have user CR3. Change to kernel CR3. */ SWITCH_TO_KERNEL_CR3 scratch_reg=%rax IBRS_ENTER @@ -1129,6 +1256,12 @@ SYM_CODE_START_LOCAL(error_return) DEBUG_ENTRY_ASSERT_IRQS_OFF testb $3, CS(%rsp) jz restore_regs_and_return_to_kernel + + cmpq $0xC3, CS(%rsp) + jne 1f + movq $0x10, CS(%rsp) +1: + jmp swapgs_restore_regs_and_return_to_usermode SYM_CODE_END(error_return) From patchwork Mon Oct 3 22:21:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997827 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66BAAC4167D for ; Mon, 3 Oct 2022 22:22:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbiJCWWI (ORCPT ); Mon, 3 Oct 2022 18:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbiJCWWD (ORCPT ); Mon, 3 Oct 2022 18:22:03 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20719.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::719]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5354855084; Mon, 3 Oct 2022 15:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H8/c2bggFW592cOpszPOSDZTqgmXrgBfdgnpgbBoIPx3PYHEODsd4KWl57caIlnST5i0+SSCPPvaniAdLj1ho9aYYcicoKLqL+QFj3VE0hTU+0XIJ2WuYfM2WMvRDVMLPRnUnkz/HzHNCGWoGL59AaiJpAUn+l4/6oMEpMuc2HqIOISjQg4YsScyJySOYc57HZJlEERLsJ0hXOa45GfjFg6bLJpNk3h1oCMmOP0d9dciqeIX+3j0z6fZQmDvUFGyFT9KuFo0BNbtILkdjcUOQmVNZqO8r4hphruSHlJa+N5pPX1UDM6RYW5slYKpy4WS3xW8UZKis/68AXJPa2hONA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z14fAtkfPrOamaE/1DyoemSLSS4pvPqgduyW0IzSLBE=; b=MtqzAww3N9kpeBk3DJAtoib0BNsPZztqp0Sch7bC4/IyoD/uigo1pHSOfIWJQ7tdntuNGTGxrteobMNCltgNmsjwqNu2xqFQrl0NtrYP8LWeuZeX0jx672SLFTGnwanRfJ8QOZPqheU79X6CBcy/3haRy0vEPB/nNNUlXQkFhqEpxGd+dfT9UDewLGb57YeY7EYQvxdBKWyB8LtiP2euIxc0+KPdkK6/bJ3FgYiHShZ+B1ImwYHM65xBWHYAA3DMwx/oiAfHxHbMwBFVgOEs17LhFfat7wRlb2l8wbuxD2r0xOL/u4zxvbvTgqPx2ZWuaTYnp5CpAqfxaBugmDjt6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z14fAtkfPrOamaE/1DyoemSLSS4pvPqgduyW0IzSLBE=; b=YZIiCvuG4gwt7W+kRyw3GDvf0gsStwDx140Cf3mrP/xIBB529tu21wycV1QeJ5FH+v5K556TR+Scj19JbBDBApxcSyNacTj7OLSarGT+owtpLU1CvC5pMHlyMpkJ+mPM9gxKSZr8VxaCJBRhvoqN+FCynMqjArpiYUwxm+RtU8nqvN8sRPYfgj7e90mVoS48vCYBJIS9DZ4M0ZnaK58/RZJrqB6S/8CBaoqKBqEdMpmS5LcHOwTS/5wgQxi/1DZs0COQBGSP8GPePnls6w1TBK2aai3yao5Ws+HtDazuo2nXd7FGWs5iJvbF9pkOzu0e91IadvDXvyTeyO+nZSuCfw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by MN2PR03MB4928.namprd03.prod.outlook.com (2603:10b6:208:1a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Mon, 3 Oct 2022 22:22:00 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:21:59 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 05/10] x86/uaccess: Make access_ok UKL aware Date: Mon, 3 Oct 2022 18:21:28 -0400 Message-Id: <20221003222133.20948-6-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|MN2PR03MB4928:EE_ X-MS-Office365-Filtering-Correlation-Id: 484be881-c558-4b48-41b5-08daa58db07e X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RTg+Uoix2B5fSTCKIlfm+3zSWdww2Q4SsF7Hhbv5jA312gjd3005gDrgqAlE0wnhN2YnB+frQkmgXnUQMTiI92kQ7XnbJWDqAPL6bBVvUDUYhsr9yaqaCoxkZqZgcMBjtxVQYCVdptW3+VrdOEbWo5XJ/0B8x/8NMD/SZdHb6//p2mlhUIWRCsfPQTGEa9D7fNq6SbwvIg+wLwMBXpnX+rJlIkEsbJOsC6+1k8Xgtqsefl+AUckKuDQ/lr+SQoFr3XYb0PU7F0MYMY71M6Euhxe4HKvtmkkZeECi8ZDkq/cbSX/pUmVIOJHrjqZvohBwv+USHqmV3EUQd1dbphunhoQeCRJGUVVkAZ0pAJLlxh0m8XVIpPFHE6K8cBv9mjoLhkOpBGh6HPwHfEHmNZRZtrk/XCEQLn+1txCWa+DKAcL/K6WJ38tTEk8kS7pLL76+kKlP0w4ilaS6cxp0EvA0MbfcPjMuM0BRMzYIylsXlBChnTiuOCclgR0/scrZtPZ5FEjhxVIxYdCCyNMfw4YPSAibboy1aEsXmCE2Q1w6Ye6kQZ4gm9vVY8UtkJx+vlthGyTDrM/kxoYky6a2ralKNw/9kHc9Ccxc5qTmGsuh1vxW/OhFNryrx0wekymKRjyBt5GHNBrexUozNvBN1+EQV0fx/RAuYEGhwd7vNLv0zX8NU1I3KjBnVW+hn6oB+4htZC5MV3FRqtPoTAksYf4U6sw4sAP8uwZ8vnQLltxch4jd+Kump6I1LerAj6U9r/Csk1EGRlTF4srtx/TMux4m7A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(8936002)(7406005)(41300700001)(6666004)(38350700002)(75432002)(66556008)(66476007)(4326008)(8676002)(1076003)(186003)(6512007)(2906002)(2616005)(66946007)(83380400001)(52116002)(6506007)(36756003)(5660300002)(7416002)(26005)(86362001)(41320700001)(6916009)(38100700002)(316002)(6486002)(478600001)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yMVUkIQVjLTMlW/7DtvFo6XvDzF6cVW0jWybUzfL67VrCG5x3TQSKwDajKaEjj/7nBbmlYH3EIPcIDgy/XSaxZss1xed8JLlJrrATMD0Kz/ojy+fUQVO+BU5os+8nArLW+09LqxeRp4Sa8LvvuAhEByXx56md5dYXcKVLUyhREk0Y573zf9piOfkBIEzcEiwFCRIVFohDUuUP8FuVYWXxjUosIR+dEnfdtAx1QtDLRtz50gyT4NBbQkf1kGNqLeq7wItyR/C3fsi/dG8YZEKCv+Gr6l0UgibkuUIC8RHTkbsKvpjEmSyi431xxRNPV4IugJzh8diz+kgtb+VZJd3dCNPNDpYAPkpQnAlvkNSTm7qbZUXoV96KXBYSXbYc0YJwiasRQkLre3ZCqO8B4Ye5iR562AyYpkjM/0Jy5b0UiHWphTbOXGBz9TsPCvWz4TI4YpUpDZIhQxQ/P4XR+q41if9H9GZLKQZO91z2VjFAQ+7xERyfapx1j0NXtF5ZtIDJKAnntlS/7GYZ5LU85a+ToaI5UukbnX5xcMMdZg1swAtyQcr2NL9fv0iPfvxP4C5sx5BPaKJfXPvkfIrnMF1xjVKB6X1be4NATRW79r0S9u8wdRj6pIfuGmSJld6Prjk263rFa1c52suSRHRGS4EcDA1N453cFgIc2Hi0A+JXlzklfISLV8PZTdq5OnF1ppdfLkyGD4ylpp+kmoKHE//FcO98U5IfRQ004uzHwuvBFVZkIo4T9hIRwAt7z1F05OtYPqLaJgSVJCv69TruagLZypqCAw4Sj9dQQV0/mnSRrRgzfZtrj+IXZpkLL3DQFr2VdbgaoMxGO9Y6mUyidECvIEvcR8exTKHhlOKn/XwgEOo9muo8pvRm6j7U+CGlPAziwHErEGddHdOeWY8HAqKOhAW14TwEk1ps8bcdlkhJdeWsKX6CXYxho2/LhYM+IF9xlEiYfieTRaIKKhqycSPAYWNx4xDkvfOLD6AIeP5xHdKDtXY3WtJ5anBtqBYw5AEBcT2DkoEJgwdqLVNbpeOgz8lRnu5V4/R1qiOj3CbQTB9oayE4S0aLwjFOZvGuhWsMJ4j2Npap9KUoXz0tN93NL5uLSpq5QwxioEiEVl42O/AtVBIgl9N5vii7rmMjLBVFFW8ahQmk2RudqKalvWmlHtIPTF0f2IEBvWdAXkvJqAdCQ4vapkDvvrybxrtkt4j0grrAH5cT2Us/D8GNOYJgCyiFGmvutok8MLkEopdvuLJREfsdubUp4Gkjil4yAVK8CqDs8dkPoWhDDXoOTW56oRwKXjKds8NE4AhKVpQQ+6ppL7Iyax+9UYHjSsOzPo7/TvL83uG6aHuQm5W6/fpbxI45yAcpuxKlk5TrlfC0yb4YjaQ8Rm5/spemOn2VRgEAoPJPp8y21sA4+U9JGyEw6ME5Lnx5P0+35Zstoiz/uJdP3j6BX445RqF+i0ch7aWZPiDwATq38XX8G0jIYbwufLqyh7twXaGe/3XoTzD1dbhBjsItdpRI7rzwqAoEbtrRWn8qmjeuudOY8HApPUVmOeVaRt/ANoig9XnySlxZ59eddo5laROzPTEsUELEcgh X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 484be881-c558-4b48-41b5-08daa58db07e X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:21:59.8569 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0BvbyvWu9cfqSMWbOj4598Ci4AQ30aqpBh9YIiwb+3nOGLA4icfHnHmgQPFZXIft X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB4928 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When configured for UKL, access_ok needs to account for the unified address space that is used by the kernel and the process being run. To do this, they need to check the task struct field added earlier to determine where the execution that is making the check is running. For a zero value, the normal boundary definitions apply, but non-zero value indicates a UKL thread and a shared address space should be assumed. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Signed-off-by: Ali Raza --- arch/x86/include/asm/uaccess.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 913e593a3b45..adef521b2e59 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -37,11 +37,19 @@ static inline bool pagefault_disabled(void); * Return: true (nonzero) if the memory block may be valid, false (zero) * if it is definitely invalid. */ +#ifdef CONFIG_UNIKERNEL_LINUX +#define access_ok(addr, size) \ +({ \ + WARN_ON_IN_IRQ(); \ + (is_ukl_thread() ? 1 : likely(__access_ok(addr, size))); \ +}) +#else #define access_ok(addr, size) \ ({ \ WARN_ON_IN_IRQ(); \ likely(__access_ok(addr, size)); \ }) +#endif #include From patchwork Mon Oct 3 22:21:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997828 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B995DC433F5 for ; Mon, 3 Oct 2022 22:22:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbiJCWWK (ORCPT ); Mon, 3 Oct 2022 18:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbiJCWWE (ORCPT ); Mon, 3 Oct 2022 18:22:04 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20719.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::719]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61AAE5509E; Mon, 3 Oct 2022 15:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H5JvXvyGZ1Wts3f4VV7VUtPuN3+hD7KTqZEPTeE+UpyZ3w1OJcidLibLewUNGwM2NlohIwvXdxGY6aKuY3IRjU5+3mTDu7Zw8ikVryi/C9Pc6kf+mWO373A6sJBIvrkF46hAnn4MyaEpBt7+/rWt8c3RDEz/t0vY7+f98myhVhESQzdsVPOPiPLPA5DRqmxpq9pVn3b3bM7zB+6uqfZ+GAa/ds+EnK6mp47IxfZSabT9v44Vnd1IwQ8ZNkpvDPDosdBf2CblIWH7JBz1xsJ4r/hXjRR9O+oe9GVl0JSlVL8c1iI2flGFe05KFFRttQeZS+7L7yepADj0w9WV+iQWAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OoLludXIvj9/dFEss6wXJs6a1houVrS1o/ZDErKipS4=; b=kuavkvcT7OsyeSPDmED8U+xgJfipFHg3mCN+La/CguiwtWnllUwCuX59JdJ0rb3yPE6PBC+T6kaQPjSQ1eUz/u/VSthTlzik1ZDFhlL13j6+20H7ZB5GYuGOQTCdvMZPFgDEaJOzWcpXGqGo5YVOoqJvoKGI3+2B490b93/NBXSQIvFiv6UKL48V4X68BofsmC64GQ+psPLZVscpTa/+K4t7MIQ5iNQSdpPWdp/cA+u4dF16jPTIksdtVatkWvKArbYj6E4fMdLV8FToVbymDm0vccx9hOdUNfgcJMmV6PQHYOxna1w4pZwkSksQO6cd+po9emBo1ZRVQUIjTQaPlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OoLludXIvj9/dFEss6wXJs6a1houVrS1o/ZDErKipS4=; b=TPByCr6ijpqhvzviE7nHWyUiBODOk/W5byNNKbOskpmcCHswYR9Jbnw5QllNce+M8Nkr4PGgXIBeBfstfLvOsuRCJesJbBRT7ecS7UZP6B2lW1Aj1M+yKjDiQoXJCwXwiCKmQ04GcGWT7UzOoK8e4g4kNQ7FNmqepkBIK4Sh7kKCT8s0LnBEYKq8nAprOGjbzkDA29wh+DNsOrYi2i40BxuZ3dppD0vfsZghoahAh4C5skQIGY4ljYoLuHzY5EJnfgWu3JT4duFMEFZEXcLE5gCYO6prnexBjO2Y1QxxHJRdz0HTcDWhtCu3q536LfGfg2G+e0G8IL2LE+oQpSOuRg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by MN2PR03MB4928.namprd03.prod.outlook.com (2603:10b6:208:1a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Mon, 3 Oct 2022 22:22:01 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:22:00 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 06/10] x86/fault: Skip checking kernel mode access to user address space for UKL Date: Mon, 3 Oct 2022 18:21:29 -0400 Message-Id: <20221003222133.20948-7-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|MN2PR03MB4928:EE_ X-MS-Office365-Filtering-Correlation-Id: 9a87b478-7197-4113-10eb-08daa58db112 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8f/R1ivFOIpe61oGnzjp4VZk4MizdUuTPVPUtJuu0Ndi2TnrOOLddTPrOKMG45NNew1PS57VJkN2wcIMzpoMG+vNuTN1nTAZzSBXB4XzxLRgDjlmS4ysAuhqzhbevExw8xJ1d+JbPYcAMjwwCL2fTjyMjZxY0rvMr6FfhlRI6XslE5V1b0yS5l2bCNWVQfNdSiDuqZfoKNHaaRyqmx4aPFCxChX7T6KWjwbcOrGQ3L4YZL8KOojnCy5r4eAqR+J0CWzMx/4wsmRNrPzdM3TJa0gWd3Kkq9tGdtzKkaQDkNxrOGwzzS6Ed0I7B1bC5DM3OaoVsIGJPrT6EwUxl63YCb7lIPSZ2iLoBuZRPTOFZCtA36r9oIWJwEnxHJajirplHr5dS5wp4L3VYYGEe++6v0TjlybXYocA/IjcS9rMEQMdW1hQ+1L2aaaAnu6nbQiYAWBhIEkZY7OPsfhtkK+8yw7VQ9+paB6Ok5HNvi8+Isn78eR3NePwrCqrPI2+zv5ShkTK9UWcvCQHNx0A/Hm2WWC9StzT53Ia0KgPYcoGrcso3Aos0yaszCV5VzIxq5gZbdS3XoQV4r6VPms/SIZm+jjXheOcmZ4soyzB7LC33YTu0mXb+M3bRHd82Z8s0Bp1I7nTVX0EWrxeE+F21knKnBiJW9U9wHCkdaA5d0AV6YgQmqfmDKXEhH0k4XH6x1ZSyZ4IwJ8IwTHR33DEurI5d3AMlgt1s8Jx4PlFV6gMlP9xgbodAweauS/a7m+VfR2CQNlgFUyljMj9axls4Tc0VA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(366004)(396003)(39860400002)(451199015)(8936002)(7406005)(41300700001)(6666004)(38350700002)(75432002)(66556008)(66476007)(4326008)(8676002)(1076003)(186003)(6512007)(2906002)(2616005)(66946007)(83380400001)(52116002)(6506007)(36756003)(5660300002)(7416002)(26005)(86362001)(41320700001)(6916009)(38100700002)(316002)(6486002)(478600001)(786003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YWYUYFyfxDihmPhu5mscnvN2afmKzFQlS/UU9QaMC4VWsNNxRxDY3sYLthJ4LHDRcLw2BQ3Fk50FYXTH3BUQS4YSZCo/aJv0lhajficycah79ceunot1LhoNNhlnmDGyidzNx9quHyGKVkLRDEwPAEApgrl/jmVGva0n6xdKZGeD5DUvBDjYz+RE3GjvuE/dgnMLxoH3uwSwzbyG1Jlxz7KSkwtXafjLxst2fLOLvpQ7rG+ZXu5F6VkC6JVmczwLAcaaJqv7Zx2TsA2ogBP9unnvhqE9lG+FaSeJ8yvZWog/SlAsru7BbjxGcIz2YLGserV6UVIBpPB7ATQrXXfzFqtw3uiQvEZzRehbl+pliyolRzqF7KGkeVKxXVKU9uNNt0dmwES4+rhSc/RPFkGgtYLEkL1ziKi84ocy0KN6DwqOgEKex6h6pO2vwN5q+aQqCST/GxlYXP726bF2yDR2SLk+2SH29yEoU3d7xhKXaoqCy8oy5F7G/UYOZg/C5oi9nqAJps3eVPA1LS5uSwnlaWrsSnWhS3D+JvSkyPO7srdHpNCsEkvBpXASljXrMlp2zPChxDJYb55ffM4wnYNPEVbE84I7pjag6wyrodnT4wLgHBq66JkCYWAhHeW0g0AsaK+5xqGsSj5S2fxhcAN7czq6OjHLsdlmMo0BTZ8RjvTnPmLvdtqpK8SgQ0L0e8roD50p46/z+2ESBzAWQUOUfjtW4XvBP8Kt7uO6SUcsPx8QqfiYIKnJKN/oWdHofU1PsiODn1QTMmD2uJzTe/MroHEF+emNl+rU7Y32c7QAeZ4DWO4/DggEb3Kipr5CZmPgzMedSm9ztr+2L7TlvkaAV8oGcLW0q0inhgzxkHzMjQm9/VvxbTdlygb10yYCHRksen79DetWp7o+jw551SvI3GMCMgiJxsz1L7A8QDCV157lUzjthi98+FIHhBRhhpZ/SabO1qlzyXmRT60wNMqy55ez1hF6wXwurPvtlBvOUfeZlrRjUCMPBmEIQZEyLE7fy/9gtZmfZLuduxPQq/l/c/AxCSrrQwR5J/FL9A8lt5V5lRIiCgGT8o6u/dk4RZ5eztpGY5h4nPbTo/TJfz10mSmkCYh+enmK5oy7ooSXo+r+UF0UYZ8rYE5vki2ReMt4xCbrkxP6VXByscVieAfAKn/uS3vSSA4ikcG1O02GXRNsLg3Zs0sfYt9KSniNCkC08TDACwQmuYz+yS+O7zvqRBw+vW5xvqAfu4y7+Rha65WjT23b/92cB6nPsEJR733OjzRT9axGgNkq60WV0lkOK0tzgnz43SSN8Dg2usRi3OLjEvGs2gI7zQOmg0AlFMWOAER4ztjOr8+0XkQRD41ckvq3Tb9I1XmK/3bAEYb07crA8dhx3U1vrVhQ4A7/X45pBlX5UGa+v4FV66qcguPehCCJKwikwLRSRqgklS9zo1ZIYpGkLTdWl01oLan0rHovjGyhNf36Dby0myT+8dHbm/67izTPNW8zbTRV+0a2aDvNm62YRZRT14FnraSWhdnpFDBrVyppF8BCLhISpNaT9gW4Op1f9rsg+SRuTxLsMV/Sw7sZpkjiYmN3AaILMtJS X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 9a87b478-7197-4113-10eb-08daa58db112 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:22:00.8256 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TjjzY3rg8+0uhjkvOXopfRWUFP8B0XitVouupzt97577gDU2uCc6T/9kT+bPnFwq X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB4928 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Normally, this check ensures that a kernel task has not ended up somehow raising a page fault in the user part of address space. This is done by checking if the CS value on stack. UKL always has the kernel value so this check will always fail. This change makes sure that this check is only done for non-UKL tasks by checking the in_user flag. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Signed-off-by: Ali Raza --- arch/x86/mm/fault.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index fa71a5d12e87..26de3556ca2c 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1328,7 +1328,9 @@ void do_user_addr_fault(struct pt_regs *regs, * on well-defined single instructions listed in the exception * tables. But, an erroneous kernel fault occurring outside one of * those areas which also holds mmap_lock might deadlock attempting - * to validate the fault against the address space. + * to validate the fault against the address space. However, if we + * are configured as a unikernel and the fauling thread is the UKL + * application code we can proceed as normal. * * Only do the expensive exception table search when we might be at * risk of a deadlock. This happens if we @@ -1336,7 +1338,8 @@ void do_user_addr_fault(struct pt_regs *regs, * 2. The access did not originate in userspace. */ if (unlikely(!mmap_read_trylock(mm))) { - if (!user_mode(regs) && !search_exception_tables(regs->ip)) { + if (!user_mode(regs) && !search_exception_tables(regs->ip) && + !is_ukl_thread()) { /* * Fault from code in kernel from * which we do not expect faults. From patchwork Mon Oct 3 22:21:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997829 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E22F5C4321E for ; Mon, 3 Oct 2022 22:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiJCWWL (ORCPT ); Mon, 3 Oct 2022 18:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbiJCWWG (ORCPT ); Mon, 3 Oct 2022 18:22:06 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2137.outbound.protection.outlook.com [40.107.244.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C787550A8; Mon, 3 Oct 2022 15:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Iz4BRlalncUCjNQmN1JsYs36emAhRY3y1S5R5X6k3YgOfUHQ6pX5qlRpm2m1alrR/6sLMxBMjB/sXY/mnKjs+afUcnmRq4L1+d24uOBFKlYo44a4IOmf6oXnAQ9taMk8m/Ks+l4Hs8lnZovx7E9fx7bkpISNB4pp95cm5Cmf/coiBaU+VEwvC4OlyHvAUgrK6KteTvHFQ8sduwYd0It93WzB0Ks1adeG9SJL8iYADMcMU/htJJduQ7gl77exGZryc0qgGMX0o0tv0DA/DUkEU3PlUAjpjg4DucHV/SroV8RZqnZALfIOIjGLShtDBN4MTFlOOlMB7Zio3kPQwRm6CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BjPFCrEB1SGmj5J5Ix6tTabj4drSc36AnHk3HRtrIsg=; b=WUlYEhRo3eJmnIolAhif+oIKDerGhxZWBBX8kBcDJJp4VaXzB3tcUzskl3AzytC5uD6Yjs/Ac9EbCxl96KlF71GUYNAURKW51qa08B8nmgFIr+FHB6s/dcFJ0dDjOC0/M7K1U8T7UrS+EP71Z8fewv+V2T6yBbcpFR0389riIl7UnffgMPs5hfLET++uXmTqYyPQe+52PYqlsoRGibeGAoxUPxZmqT8Dev2dKxbQeNhFMrRwniITmID2BGo3IqTg4QhSyhx83E0nMbatEwknA5GicpTX7Ftt5E3T8fs02c9jRmeUcxy/QvQnnXzvHxNsy87jg2zhib7Xk1REFUir8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BjPFCrEB1SGmj5J5Ix6tTabj4drSc36AnHk3HRtrIsg=; b=dUu0nlXgMxEcknq+5p78Xm0UPyhpsbidoPjjHFFYNwPx+hQJqssqKTsmsF8nI2wtzQ3LZxJO69QNfIm/4ScBf0G4oRTp7cMkrv+MQfZQlI9hZOYZMtblUyBdqvmEXH+GUUm7KCJet/8rU2tAuv/Zi6qnbvYwJMBfY/8okzzFiepX/7AjDCEaa8r6da7rg+HH6NvFpjKg8GwtuHpr0q30BlM3qHdDgcoF4rONHhpXm7+UXcbKcQi/zeIFzUnzHpbuWPVwHPggTLl2UOH0XM1PyvMj9WovhKGEJ2ykySJ48SMSqo8KqAFuPSBDghj1E+Tbc5RGhs6AhiVasHRWMTQfHQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by SJ0PR03MB6270.namprd03.prod.outlook.com (2603:10b6:a03:3ba::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Mon, 3 Oct 2022 22:22:02 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:22:02 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 07/10] x86/signal: Adjust signal handler register values and return frame Date: Mon, 3 Oct 2022 18:21:30 -0400 Message-Id: <20221003222133.20948-8-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|SJ0PR03MB6270:EE_ X-MS-Office365-Filtering-Correlation-Id: 94929797-b5d6-4e87-a4ac-08daa58db1aa X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bSpd4QtLjnrXfe7PfRk3eMM/9PorsNWWJuH2cAoPmbVP/Mw1tRt6/cjzU42FAlIyhUP0Qb1Z5fvT6Yx+DbR11ypc/jJ9/hQyE9F3X4RIqNIMTpeRBJUynDoHg4y5ANq3FlDD8+Vnce/FrrTKhHbBuYSjnj3AQhZ2s0iCM/L/61wM7dO5ydCzsNXXWneczmfZGpMY8/3gxkWI2GdBClqtiM62Wkg5KDJbvXU5DnJw7J2BR7uUSh805mls9atf+1WNr5O+N75X6vh5aJDSqNMSaTe4qfqp/WY15adZ/GO7ZKhgaYr0/Tnd+4DFgUHvzdof6AqBtaDeDRDasXBfHbxarKsSCCxLCSvE8YiHkRNpPNFp9DI403+4fgIf+PcIanAUoA+Bx/Iy1h7cs2Bokl6YeH+VqL3CAwQdo+DzEQwrzyt+lAkX5AOC6bSkkVhCYsDDPF/2bxW6oaFO+bOBifGF7BJyS3hew81FgJjjj13ER82tWNy8dJAR6APwvpBr6FSovKmjA91K/80cHm92vBKGfAAwtcAnonyCw6sxpZMEyc6ulQkwwHF5G5fQqsfoBPe+cpLeLZtpZUKlj5E7R3eo3yrcEOaTjPtDq8oFFu3xaW+5PzeOZ5CPVedZ3EKekIipEr8FuCiPTsMnAWMDWJksifnwOFHktPTQkRadWIO3iM+UKan/PbYtVRgMBvE0KJQyY59HBLs324M/3CnTmJ5JkgtFpWS7VGc/GTgwMk3X8dZEyC1voZ/mp8xGezYRtf5soW5ZRKjiwgk8HggQs3qt9g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199015)(52116002)(186003)(41320700001)(38100700002)(38350700002)(8676002)(4326008)(66476007)(66556008)(316002)(786003)(6916009)(2906002)(7406005)(41300700001)(8936002)(5660300002)(7416002)(2616005)(1076003)(6486002)(478600001)(26005)(6512007)(6666004)(83380400001)(6506007)(66946007)(86362001)(36756003)(75432002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7mguedHQm3C0aa0NIYcVIo4ihqwwvd5ISDazngCK2quctDCgT23db9CntojiAbrJYtwco/zgnBWxRTFT4g+tNtEyvMmNWdlh4H1IgCAaEBtySs3MhV25MuoJkHKRlheQkiPhlAparE1NrllPVuPe4QDVuBh+Gi5WhDEJbxk0Uh6n4k+9b+d15gVz2fSQBJ04XTpiTerUOCWm5mlNdap8n8Vn9CsiMvEktR5ynNO6YJ0YkOMkpS5eFq+GCLwuJjlqcKG6K1I9wVGZfMGFXKQ7grl0KS3Z2YvTEIaGq0GXOPdMPhTeS5CAuikjTyyQav8piZ2HDX7OIqXeud790ujLRuWz3082jrYkgR1F23ylhrB/p7R/D1sURI6Upgg8r1K2MbCjuDdbUlJrlM3H9xNGsx1NK42W6vxBUuJXeZBrjOcsYcXWJt0UsEoJb6htjS+it5I1bx2a9Sr0DMYPAEWYSDcT1nXwaBsz7iikBnGvBsQOEjcGqWeaExrTVG6k0muWSn42cyicZbGqQnhowHKAvJpn9VRX4dt1Hvgu/iauqyrw+HvSIaVU09jMItNWS6W1MzKhX/JBjpEXtnTi7FDkAHFs0mpxM3xXWv2oLsLO1/XdQeIRKK/p0U7PR7QNdS5brUUKcP+gFmmV8qJi01vXq/YuWeWZbbcBNNbGpYCLDamz1uoPGYQ3899f1BkQLDRPVAFwyth+6/zkRDUwe4ZfUx3wty97n6fg3pzfDGKJKvZ2v3hrF81f6soTrtral7QXWCWxkjurzEnU1SwOR8f9TROh3Izw4BiuLiDePJ6lGCa5sVLc/eQosOIsND1dVTWSqdnqIXiH7/nt23quK1EH409N8PBRl1mds7e/wnq6PqOuyBwdD5diIgG+vnFMIY5U16riDMOr31QLfOMuob3pwUugKGJjQCVWTjFWMwBn4yv24wrimWBo7YgqG6vJCP0zZ4tdJmudba05CZZVp3Esqpy64bBi8AiqUTytlzI3mDqSvsrckMRJ5yKkLIBdQri0D2PdnFnCPuLz31BibHZWrI2cVW+LEdWRwWeOHJcZZKYXV3Ke56vCzf1fSUEu5zHuyWvGZ0M+iBVvJZKlYCuHcD7LW2yxyGzFjdhnLiniaOCNQkvjvBai5cOeIFLaqQob3AM+noz2BFsxw7eMgoPrDckILArik08wvyfFDC5gC3SmODpmqE6FJdL6rRBm3DdciVz9bZ9Phk8C14KTodUwNKLw+J5ki/+WfwezLAWaT4Cv6u0woFXVoSl8sB250STJy2ZiIuPgdpZByZpwn6aHI+j7P+Y96ItXss8Ke9SJMKdKjrIJjaXtceP1+B88VcvuKnFr35+VEiv6oDrMWN8lU2HJ6xOIpoq+w7OC0syJRzm/JZfFZvJFBUOT+oPXs9HX3kwyhZ4y87aP4F0TyGjBkr6PmZP//poDHM+r5bAVDqUCfATusBp6Z40D7pplzIxJa1BNFhxEeFobkiopyGZbgOmMReJ5ZDY1buZgm1y4/wbch4U+Xc4oY+m7l53AAUdT1JlMufUWf8BCru+YULTrmAhIYKGRF6zEkQf1hA4HhtNIzCs4abWtim8mL4LoK5sS X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 94929797-b5d6-4e87-a4ac-08daa58db1aa X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:22:01.8724 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oUQ3oNim42MNhsplV4odpA95OswXRkC0rN47swyUyfgW4SdQbh9jg568lBtxPC2c X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR03MB6270 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org For a UKL thread, returning to a signal handler is not done with iret or sysret. This means we need to adjust the way the return stack frame is handled for these threads. When constructing the signal frame, we leave the previous frame in place because we will return to it from the signal handler. We also leave space for pushing eflags and the return address. UKL threads will only use the __KERNEL_DS value in the ss register and 0xC3 in the cs register. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Co-developed-by: Eric B Munson Signed-off-by: Eric B Munson Co-developed-by: Ali Raza Signed-off-by: Ali Raza --- arch/x86/kernel/signal.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c index 9c7265b524c7..a95c12f6dac6 100644 --- a/arch/x86/kernel/signal.c +++ b/arch/x86/kernel/signal.c @@ -121,8 +121,10 @@ static bool restore_sigcontext(struct pt_regs *regs, #endif /* CONFIG_X86_64 */ /* Get CS/SS and force CPL3 */ - regs->cs = sc.cs | 0x03; - regs->ss = sc.ss | 0x03; + if (!is_ukl_thread()) { + regs->cs = sc.cs | 0x03; + regs->ss = sc.ss | 0x03; + } regs->flags = (regs->flags & ~FIX_EFLAGS) | (sc.flags & FIX_EFLAGS); /* disable syscall checks */ @@ -522,10 +524,15 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig, * a trampoline.) So we do our best: if the old SS was valid, * we keep it. Otherwise we replace it. */ - regs->cs = __USER_CS; + if (!is_ukl_thread()) { + regs->cs = __USER_CS; - if (unlikely(regs->ss != __USER_DS)) - force_valid_ss(regs); + if (unlikely(regs->ss != __USER_DS)) + force_valid_ss(regs); + } else { + regs->cs = 0xC3; + regs->ss = __KERNEL_DS; + } return 0; @@ -662,7 +669,10 @@ SYSCALL_DEFINE0(rt_sigreturn) sigset_t set; unsigned long uc_flags; - frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); + if (is_ukl_thread()) + frame = (struct rt_sigframe __user *)(regs->sp + sizeof(long)); + else + frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); if (!access_ok(frame, sizeof(*frame))) goto badframe; if (__get_user(*(__u64 *)&set, (__u64 __user *)&frame->uc.uc_sigmask)) From patchwork Mon Oct 3 22:21:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997831 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7586EC4167B for ; Mon, 3 Oct 2022 22:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbiJCWWN (ORCPT ); Mon, 3 Oct 2022 18:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiJCWWI (ORCPT ); Mon, 3 Oct 2022 18:22:08 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2137.outbound.protection.outlook.com [40.107.244.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F361550A8; Mon, 3 Oct 2022 15:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AvWC7dP+nAyz/Tur0QvGr9zBQxLung8farDkz9PpqwQBxhrr4Soqq5i18Z5mgYnj/1z+Ej9HiM8pQKpvMcijbi+QYm7nzM7xiOIQ3pIqstLsbJnfec/uFdY3twJ6vkZpPjKg7BaiU7RYPUWxQStaHQGgML9ByoyoPuwx0RK1laS8WlSHwB6CO777uzZmXFyRwTq0nE6MpFk7DmkxXLJq+No49DDI5hgCiOAlL/HBQ3cX4mHTVhtDmxo/DE/zAZMrB9J7Oc3ZofRhkavL2CwGXvdGXRjzaHW+oQYNBXBEouUKjfdA60Iv1oomUMwELa+RMficC61Bno36qo4lMJ923w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jaq7NPEdmF6sLDvhdoNRQ7kvkb7UJg1hsFjyRbdXRlc=; b=T0K/XUuj8MfHtuq8eHoUtAwv5kXwpsfWzYiuGOy69hvuTZDhSOUYAf4635q7N9MAMp/F6QZnbqnVFP1xcW7fkq9SAig8eLpUkCrpr2PHFAf15ilJm8HLd26hUXsT84Y7PAGUS64h1rjRk2OhSJHYfoVfDtbVQSDn+esa2bPAkv3DOyG49yFdLLd6+dE+214LFw7c4TbGSy9QlsRfOHnKYkGdhLuz5RlHb48fXptGAxkWmllnnVgb+1mimVtIbPH6rwxSkPK/z4MdWOAL/gBXEUuckZvIKT8AXzHmRdyX2jP0EmxElpG+0rNwlynGfHlxS9TaQHlj6iplReosXECZ0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jaq7NPEdmF6sLDvhdoNRQ7kvkb7UJg1hsFjyRbdXRlc=; b=PEr3BSinX07KUs1LnIyoUQm+izp5N/7swMN9v5j/fWdOOwulg9bTmN5v8qWGylFVDy8GjRsqbur+ldEm3vGwtzx+9ciK/0gqIiTV195Bp6HwOBi5zGfsYtoidojidQwbIklfndzr88t0BkeeZAvjceTAh5nmebBSnJN6E5V82SPP0vV7Z2uwbrl9lPIM5nTUqK85z22MTAbhFaplQu+kNulaDrYUZlPenrJYDCK4/974W59OhNDIcjRwHK/BHGo+G9C9jRaGZ/xKgSNZJiiKb0WNocxGxN2aeaiosVcN/2P8XCHWUOtvXsQg4iE5uLpWYOWcNmItviuYhsVy9QawGQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by SJ0PR03MB6270.namprd03.prod.outlook.com (2603:10b6:a03:3ba::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Mon, 3 Oct 2022 22:22:03 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:22:02 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 08/10] exec: Make exec path for starting UKL application Date: Mon, 3 Oct 2022 18:21:31 -0400 Message-Id: <20221003222133.20948-9-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|SJ0PR03MB6270:EE_ X-MS-Office365-Filtering-Correlation-Id: 89f3e219-0efe-4349-9aba-08daa58db245 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AgkXhGH2TTBnkNVk3OscN+0gupR9Ul1vdv4Y+Q1Nod6jNGQxGj+1LnnvzpxU58W9TshqWcWZ+9+Ddy7xu19ZTGsQILwx6trRkJB3b3QrgKLfY5q6aHsQNduVT7MfEmp7ZVUT3fKDgK/fIge1Uj3ZvutUh5txf5j733+kqNVJT1HognLDTgVUHgyIERLdK/FqRBciqAIQC+ox7dW9nDTQ685RC9L48ipYuoBOMBsF/huKdyodoAReHqMeEZbhB7538dJQDiLRj6wVf6iYf47ZPucqShWUMn1K6tzCHIwM8Of78QVYPbvDzzetqIf/ngtAn86IIKRYCU8MuAOInbiaYTU7y3jxmVTfZGWGI5B9AI9wTznul2PRDVoGgWzxg5J7S0JKUzAIyAiR3CuLQlMVaCtbwVZF13/+BaBuR4G1rpjdiahaPAZXnsvG524V9dYXdoAaEYB+x2+AAZpAJxaui853L8NwcTs9m9h7BphltDWXwybALThElcIAKPOZdWe9DJzvsSZf6LTD2FV1u0SNa9u0dWx7rULKf9FCFyBY+1LCbMbxu55tbfd+Z+6hantAdLq8zb1FcmQkyVtG7jpgWjjY6aJIFU3iv8m/jN+g3xoqbEZnIqhvMjC38jEUksqAD2rAMUAt3ztnunjSp1igAUpmQgbcX7z2xEZMl4yTUf/HRjdlL0pTxjgTcL6Ukr0WDzsqKWdmCQvSMgQLSaXOzhoE1Z1vTBXWuC6P89NXn1I4P826pmQml1Hzqf3Qzj23RBtiyATmJGqA9obHJY5DjvuCBcZWMY6iZ1LBfcMRcmE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199015)(52116002)(186003)(41320700001)(38100700002)(38350700002)(8676002)(4326008)(66476007)(66556008)(316002)(786003)(6916009)(2906002)(7406005)(41300700001)(8936002)(5660300002)(7416002)(2616005)(1076003)(6486002)(478600001)(26005)(6512007)(6666004)(83380400001)(6506007)(66946007)(86362001)(36756003)(75432002)(309714004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SoyTFAUWmyBX8nLOyZk8fOluaidxwziaalGQmGJ3nADrYqDl6I3MJtcojphtZwIMUvkeN9wD4M181BEOw4OGYCw+e6YCdDBp7+IsfcZdgEBTiYDEjxHOoHNXebnyX7vAHWIHkH2n2rwLx8ZK6jKKs63BoxGPBhyGSevPGH3JH9oTexldsBTcQm+hm9KVYparlbTPMh19590U5EcoGF/qpRrJw3xYHJfhfwy+62qusqT5iURvuhBBq46KPt2HbV6za9XLIM14ZWhGqrA0TAmLmNFtXsSgG2Sncr7T8cB4t+R2ubIknggG6gKVoum+P4EUyCQaYTIRX42B8TuxesL+/QE77tAUMLOAqus4hMiiJZgqkxyZuBxK1whuGbeZvBnJDraGkD2Ioueg2FWgpRoMAIuqf4TBwb4GK4Z7VYXTqIDX9rGabOWNDHAhznoNcQFB78lg1k6i2rP8ZmukvHWikUqYcL6JD5LZyIJhFftI8FWy5WaXxBxS88UCDathzUJl5oJ6IBSUR1CZOcU0dQ88AZkMN/EwfNyG9Y7uAkHw+NLc2c7XwwDHkcYUGjaYyHZTUuv3CzM2G+nqr5Zpn7siyIBLxBfWXRLkob+j8dj5EO3rMdR0RMcsW9hBJ729hHU6R+a48f6eyamfnuSSOeMffj0DehXJqgxxcDqvdJlPEXdf+wR0MT/4fI61ymW1vbcpfz7dJdDuLzB+nR6guKtoqfaYbVFOg43gciLIPMqTMLVdReax1ivSXgl9gI4E577G5kn4/q8p/u5mQwXsx56IuaZN8GmBeNKVZx9+iaqnOxc/oEaxlj1eZrD9fnD3URZNAWQSt9XKkN8btPHRofVC5/1J8NM5xtUTts6EAPoIs9ypIBHrextaoOqDszSykhagFLjnUP8nNXoMNoketFmoo/DGhXALnchmAHJxKobpKVRrvJD9TcZZ3Urn5X7RjaD36ktbIAp/3gd8MgZpgRN+1hPp31JfXygfk5X6RnJ6M196ZbEsYdeDabj1wilnAuVsuDMvBBrt21oAZ51PHSmb4kkeabp5Rxg6GicXBkXHquM3wRlz4J/BRI3mqZ/a6h2lF+ZbqBQpDTQMMvENM09Ze0geEUw/7GhmDzr1tPOXOKtF9NMLKtq/Wb5DBoZuzsG67y4SZkxPt+zMhNKBtk7tXAj++ppcjiXbdpWvPUphHUAzphUp3mCS0Dvi0MSH2whh5QdY73dzQtSAjTTFPL6VyvITfAXY8UyM+YczFX4SMKVLCCbQTittpgu+4pIs2lV65dkIvQaKL86yRiAGQkO/BoyrqmmGMCr1jMUn3Xt+JP59VYJMiiNWzuxDN73FksK09lIbA5ZbLNOOQz4rxW9In66FhSQszX6cAb6s+tg8xh+5lsaZrwNfqKSh9JMfWdavciV65UwAqJHkFNCtmbqeZ58sq05CPF0o/h36flxTDaXHWVNGP5pIOqVaHe6ecM5gJWl12Ljz1jTOC4lk7mCOVt/MonfxjfbeH5TK9BpV1JzVbIT9qwijalJJuarjfaA45UOtx6g4Kj1/tYjsYDM62eCN+/EdDIeoBho9tvunJyE4vK0Ie5O3Rb6he6RS/lYU X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 89f3e219-0efe-4349-9aba-08daa58db245 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:22:02.8567 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nJv+t/rrDRpzdFQGYgw42fDv2c0LLZCoCrpgDlpqQtrKLJfU1RwslyRN+jLdaBFQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR03MB6270 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The UKL application still relies on much of the setup done to start a standard user space process, so we still need to use much of that path. There are several areas that the UKL application doesn't need or want so we bypass them in the case of UKL. These are: ELF loading, because it is part of the kernel image; and segments register value initialization. We need to record a starting location for the application heap, this normally is the end of the ELF binary, once loaded. We choose an arbitrary low address because there is no binary to load. We also hardcode the entry point for the application to ukl__start which is the entry point for glibc plus the 'ukl_' prefix. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Suggested-by: Thomas Unger Signed-off-by: Ali Raza --- arch/x86/include/asm/elf.h | 9 ++++-- arch/x86/kernel/process.c | 13 +++++++++ arch/x86/kernel/process_64.c | 27 ++++++++++-------- fs/binfmt_elf.c | 28 ++++++++++++++++++ fs/exec.c | 55 ++++++++++++++++++++++++++---------- 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index cb0ff1055ab1..91b6efafb46f 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -6,6 +6,7 @@ * ELF register definitions.. */ #include +#include #include #include @@ -164,9 +165,11 @@ static inline void elf_common_init(struct thread_struct *t, regs->si = regs->di = regs->bp = 0; regs->r8 = regs->r9 = regs->r10 = regs->r11 = 0; regs->r12 = regs->r13 = regs->r14 = regs->r15 = 0; - t->fsbase = t->gsbase = 0; - t->fsindex = t->gsindex = 0; - t->ds = t->es = ds; + if (!is_ukl_thread()) { + t->fsbase = t->gsbase = 0; + t->fsindex = t->gsindex = 0; + t->ds = t->es = ds; + } } #define ELF_PLAT_INIT(_r, load_addr) \ diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 58a6ea472db9..8395fc0c3398 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -192,6 +192,19 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) frame->bx = 0; *childregs = *current_pt_regs(); childregs->ax = 0; + +#ifdef CONFIG_UNIKERNEL_LINUX + /* + * UKL leaves return address and flags on user stack. This works + * fine for clone (i.e., VM shared) but not for 'fork' style + * clone (i.e., VM not shared). This is where we clean those extra + * elements from user stack. + */ + if (is_ukl_thread() & !(clone_flags & CLONE_VM)) { + childregs->sp += 2*(sizeof(long)); + } +#endif + if (sp) childregs->sp = sp; diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index e9e4a2946452..cf007b95d684 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -530,21 +530,26 @@ start_thread_common(struct pt_regs *regs, unsigned long new_ip, { WARN_ON_ONCE(regs != current_pt_regs()); - if (static_cpu_has(X86_BUG_NULL_SEG)) { - /* Loading zero below won't clear the base. */ - loadsegment(fs, __USER_DS); - load_gs_index(__USER_DS); - } + if (!is_ukl_thread()) { + if (static_cpu_has(X86_BUG_NULL_SEG)) { + /* Loading zero below won't clear the base. */ + loadsegment(fs, __USER_DS); + load_gs_index(__USER_DS); + } - loadsegment(fs, 0); - loadsegment(es, _ds); - loadsegment(ds, _ds); - load_gs_index(0); + loadsegment(fs, 0); + loadsegment(es, _ds); + loadsegment(ds, _ds); + load_gs_index(0); + regs->cs = _cs; + regs->ss = _ss; + } else { + regs->cs = __KERNEL_CS; + regs->ss = __KERNEL_DS; + } regs->ip = new_ip; regs->sp = new_sp; - regs->cs = _cs; - regs->ss = _ss; regs->flags = X86_EFLAGS_IF; } diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 63c7ebb0da89..1c91f1179398 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -845,6 +845,10 @@ static int load_elf_binary(struct linux_binprm *bprm) struct pt_regs *regs; retval = -ENOEXEC; + + if (is_ukl_thread()) + goto UKL_SKIP_READING_ELF; + /* First of all, some simple consistency checks */ if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0) goto out; @@ -998,6 +1002,7 @@ static int load_elf_binary(struct linux_binprm *bprm) if (retval) goto out_free_dentry; +UKL_SKIP_READING_ELF: /* Flush all traces of the currently running executable */ retval = begin_new_exec(bprm); if (retval) @@ -1029,6 +1034,17 @@ static int load_elf_binary(struct linux_binprm *bprm) start_data = 0; end_data = 0; + if (is_ukl_thread()) { + /* + * load_bias needs to ensure that we push the heap start + * past the end of the executable, but in this case, it is + * already mapped with the kernel text. So we select an + * address that is "high enough" + */ + load_bias = 0x405000; + goto UKL_SKIP_LOADING_ELF; + } + /* Now we do a little grungy work by mmapping the ELF image into the correct location in memory. */ for(i = 0, elf_ppnt = elf_phdata; @@ -1224,6 +1240,7 @@ static int load_elf_binary(struct linux_binprm *bprm) } } +UKL_SKIP_LOADING_ELF: e_entry = elf_ex->e_entry + load_bias; phdr_addr += load_bias; elf_bss += load_bias; @@ -1246,6 +1263,16 @@ static int load_elf_binary(struct linux_binprm *bprm) goto out_free_dentry; } + if (is_ukl_thread()) { + /* + * We know that this symbol exists and that it is the entry + * point for the linked application. + */ + extern void ukl__start(void); + elf_entry = (unsigned long) ukl__start; + goto UKL_SKIP_FINDING_ELF_ENTRY; + } + if (interpreter) { elf_entry = load_elf_interp(interp_elf_ex, interpreter, @@ -1283,6 +1310,7 @@ static int load_elf_binary(struct linux_binprm *bprm) set_binfmt(&elf_format); +UKL_SKIP_FINDING_ELF_ENTRY: #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES retval = ARCH_SETUP_ADDITIONAL_PAGES(bprm, elf_ex, !!interpreter); if (retval < 0) diff --git a/fs/exec.c b/fs/exec.c index d046dbb9cbd0..4ae06fcf7436 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1246,9 +1246,11 @@ int begin_new_exec(struct linux_binprm * bprm) int retval; /* Once we are committed compute the creds */ - retval = bprm_creds_from_file(bprm); - if (retval) - return retval; + if (!is_ukl_thread()) { + retval = bprm_creds_from_file(bprm); + if (retval) + return retval; + } /* * Ensure all future errors are fatal. @@ -1282,9 +1284,11 @@ int begin_new_exec(struct linux_binprm * bprm) goto out; /* If the binary is not readable then enforce mm->dumpable=0 */ - would_dump(bprm, bprm->file); - if (bprm->have_execfd) - would_dump(bprm, bprm->executable); + if (!is_ukl_thread()) { + would_dump(bprm, bprm->file); + if (bprm->have_execfd) + would_dump(bprm, bprm->executable); + } /* * Release all of the old mmap stuff @@ -1509,6 +1513,11 @@ static struct linux_binprm *alloc_bprm(int fd, struct filename *filename) if (!bprm) goto out; + if (is_ukl_thread()) { + bprm->filename = "UKL"; + goto out_ukl; + } + if (fd == AT_FDCWD || filename->name[0] == '/') { bprm->filename = filename->name; } else { @@ -1522,6 +1531,8 @@ static struct linux_binprm *alloc_bprm(int fd, struct filename *filename) bprm->filename = bprm->fdpath; } + +out_ukl: bprm->interp = bprm->filename; retval = bprm_mm_init(bprm); @@ -1708,6 +1719,15 @@ static int search_binary_handler(struct linux_binprm *bprm) struct linux_binfmt *fmt; int retval; + if (is_ukl_thread()) { + list_for_each_entry(fmt, &formats, lh) { + retval = fmt->load_binary(bprm); + if (retval == 0) + return retval; + } + goto out_ukl; + } + retval = prepare_binprm(bprm); if (retval < 0) return retval; @@ -1717,7 +1737,7 @@ static int search_binary_handler(struct linux_binprm *bprm) return retval; retval = -ENOENT; - retry: +retry: read_lock(&binfmt_lock); list_for_each_entry(fmt, &formats, lh) { if (!try_module_get(fmt->module)) @@ -1745,6 +1765,7 @@ static int search_binary_handler(struct linux_binprm *bprm) goto retry; } +out_ukl: return retval; } @@ -1799,7 +1820,7 @@ static int exec_binprm(struct linux_binprm *bprm) static int bprm_execve(struct linux_binprm *bprm, int fd, struct filename *filename, int flags) { - struct file *file; + struct file *file = NULL; int retval; retval = prepare_bprm_creds(bprm); @@ -1809,10 +1830,12 @@ static int bprm_execve(struct linux_binprm *bprm, check_unsafe_exec(bprm); current->in_execve = 1; - file = do_open_execat(fd, filename, flags); - retval = PTR_ERR(file); - if (IS_ERR(file)) - goto out_unmark; + if (!is_ukl_thread()) { + file = do_open_execat(fd, filename, flags); + retval = PTR_ERR(file); + if (IS_ERR(file)) + goto out_unmark; + } sched_exec(); @@ -1830,9 +1853,11 @@ static int bprm_execve(struct linux_binprm *bprm, bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE; /* Set the unchanging part of bprm->cred */ - retval = security_bprm_creds_for_exec(bprm); - if (retval) - goto out; + if (!is_ukl_thread()) { + retval = security_bprm_creds_for_exec(bprm); + if (retval) + goto out; + } retval = exec_binprm(bprm); if (retval < 0) From patchwork Mon Oct 3 22:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997830 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B400C32771 for ; Mon, 3 Oct 2022 22:22:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbiJCWWR (ORCPT ); Mon, 3 Oct 2022 18:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbiJCWWK (ORCPT ); Mon, 3 Oct 2022 18:22:10 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2137.outbound.protection.outlook.com [40.107.244.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1409454CB6; Mon, 3 Oct 2022 15:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNYzKMiZLBowEZhp5Zyo5pLJN3D1XOwPd1UJSJhxBZLLXRTvdqXxQyDMDjcoKvo8PZv4s5o9FWSO3oKgs9GDl+7NzXFkqVVH/S2E38D2Lwpgzdqahpv1m/P3rEKrjzBH4bO4cFnjZFOAr+3UG2hpyfE5fbiTcudXFcG9JqUJkLx+/b2fZDS2BN2eMyIxnDrUqlj96Ax4TXFj7y6jwki2g49Sy06ufy+RXMo+DeDP7vcx4uQdfC99mZWCGWa3tPjmDbIFmN5R/Tu9iEp+DizHVarue3FQMUJ33mjjqZcetKg1W0x7S6CMgFgGNze1z5frMY0bPfD9xpaNfU9AAPpozw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HSSEi+Z8pjovztuE0JjVuUgeA63L/vWd9g721uVaUfM=; b=ITWS11IqZUFkfU+VXeLSfRQUMYSS6Wy+eVZksNLLnStjeBaJ+8y31AIGVJKGuPEJRdAVx2Dy+4goFayQml7Dmy8WISh+FAuisMg6f8sjx7KC+rbuJ1mKrzcYyvLKQwWcOiPuECZMkyefJAEbCLzy0/Iny+MiYPNNxIkXr6a+MIsDvEFzS9lcnKVOcFCEMZeGyvJWzCMgRsrhrfcr89zUHGw2QKBmvS4Pf24bQCFP9sO0PDj5+qKAxTtVKBFhO3LGRDlkC1pSqdbk4mX5S8+lqmDHGTRb4D4CXv1eHUo4g/VlWXk2NbWxU5ocuCK931KMr3GKH4SBd33VlhivtIwcMg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HSSEi+Z8pjovztuE0JjVuUgeA63L/vWd9g721uVaUfM=; b=Bc3fiGVEzzFk7YqrjM9qo6zL4uIL1eZ/NPi/qwUnGcTV600nAnPylIaC/csv7gWEqS9ErhyXLIzOQjwYNcV9eQcOkxfdDRO+Pte7mGzMtlIZCR3gRXz6XOvQT1SYSvFcd4N/4nBFsZU8KE7bJ4sB211Co4F/F333OuyIhsg2Xib8O1y3Yd2aPX3oz7rayJrk0rdqwbj300vyQ4Gq/8Rx3IYxSPGY5wCrThO4azyZEKuUV3rjXwK1dGIBUcy+vRio/dzoj5Gl9jWGHpzRUCZDQDBDdb7SxdFlXjbSUfqBN3poLzLbJI5cOs86ne81S/rPoYXI/IcETzmil8eDDTxsog== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by SJ0PR03MB6270.namprd03.prod.outlook.com (2603:10b6:a03:3ba::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Mon, 3 Oct 2022 22:22:04 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:22:04 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 09/10] exec: Give userspace a method for starting UKL process Date: Mon, 3 Oct 2022 18:21:32 -0400 Message-Id: <20221003222133.20948-10-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|SJ0PR03MB6270:EE_ X-MS-Office365-Filtering-Correlation-Id: 8efbe912-440e-4608-90e6-08daa58db2e0 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Paw6iN7LmA6aFMWiR0SmT27rIuO+PKneqOSbulbH0Up5sql0ID1Y7Fh503HWtP7/2rGGr5Rt25ztUXnw4vFVwNt6CQ0rVLMF5S2UyyauBw0pM9l7PPsCqveWO2+SeBNAR0HLHhA+ODvhSSJFf3f6jKjorYesDVzhFPYW3er7ICWxgnqcz7JR6Df9aeIuaRUwtgbt2MBDUmnu3DKMH223uyZMhiIpFIVjPNzHb437FO5jnop0zDPl3Z/7fMQSmzfF2aAIrxKWCB30w5MPjbBCcD3Kc2WUCRYPAV3hdyrDrWw7T0/VPD3/AJiH8OUFlUSZPW/uJ6ePFBbEdW7j8wqV4cI2o29Ne/k+fLal3XOoLjReTPfkyxYmTXbIdLOf0byBXkyywRMipHKuo3/aGRGuC2EOvxiEkm+pL34EdZz1FVQO283wHeNPFOUfV6S3QBs4YVxzLW9dHOTbILlj/BEzlj7k82hgR8+xIwjgUpLFHSDnM/cshDFFziLjYxIF5rN7umLW+obS1R4G9qQavILPsentSVLNmIxq3KhnSCNf0kT5ZSXWd+b4kAvKgcW/1qf7OWyqiXxq3H8Ig2Iu7SyCAYrw5ayQxHHUOFyas8FWDSxbxcTQdhXcLm7BSnwnJnjXlnQUKN8vqTqx55oZhTUq1gp1xL05L5TYZWqVI1cGto675dvquQgWihdzBUTc7IWEB8tSGl4Z5OUohgFnJO/OSW5AxvTwhdEn90YkC60sPWAxJZPpNNRP3i0P4IqeVMcj X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199015)(52116002)(186003)(41320700001)(38100700002)(38350700002)(8676002)(4326008)(66476007)(66556008)(316002)(786003)(6916009)(2906002)(7406005)(41300700001)(8936002)(5660300002)(7416002)(2616005)(1076003)(6486002)(478600001)(26005)(6512007)(6666004)(83380400001)(6506007)(66946007)(86362001)(36756003)(75432002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: moJLYLwKgIlwulhtLj860vxZH+dljt2Eyg9vgl/yyrUUbbMbPx98pPJeospKyxmt4WPYiCTzT7evpyxLI1EPUfHYhSNKViHW+pgVKBKP3dvPnrzzOPR6gxpFmBrZODeDa6VQTRTAScuGxl2zEI8SkHYwaE7ejeFE1CNWjViaBY63MwZNv/SwzKdYjrTUzmfsWzH54ej+my28dffeYMYmq0ZKLh7RFT+MebKA4IJCYdmTKz40phpkHp0d+Mk8ApeMG3NqKrz/6xpOouKERzUb+N/E9aFR3E/fctR/Flf0rqrMAwlfHJRE8T+8ml9o7shGak31TmsYskZvNThKhqcSgpEunvhjxEHzqykZryv1XZLUPoaOBdtQz3atbVHbYA6i52XAcFQB4a/H6jnGXi9Otxwmiy2ZAzNSZNht33/dS/6LZ+/c4moshu+GTJ7w1FPacML/QZv2ulczioE10I+U0YZCOR9yskHSq4E2vlB1zp7V6+kc2sm0mNj0jglXQ4dkGMXuXt/QjCaLsXpvjx8lFzFpndvr7FQg5HFOB649S/ZPkuZsXBpQnvxLM3MKZ2olDYgoKx8OIQDhmr42HFHNjlIyMiKgUIrtprD5yMQq0mSv9cN+bO1pLs8TM1CfuSYvt52EnGYS6XXHlWGoiI6aySCt5ylAZrypzF7GYiUJVjbUDbs8GTffF6bhnRQ9l0y/Vq2Jly3LeNhXWYqYirVinQ5r5OTp6E6wBg4z0FnTgRGmXxzUemcKbSYw+aZQkUP4XnoNxIapCu4I0T5Cqqc9KaSuog7VwgKMTI4s1y/KWldZiG5U/1ltT13ksFH4aahsVboSDxOMTHc0K1bwdeXtcIyIK0DHbecDVqzLpgBQwu7FHLWROdv/mafiuLjl6pw202CXGqHwMYQtA1Qg5IEYQkBj7TUsyQ2NGXzUFvK/0SE3+87sUHJ43GXvF/2skWzKkKwkek3++xnBvzDH0mQ9I2yEY1lZT88WJ9sbTF4YY2k7cL9dzqX6aeEUpxo3zZKhTpwWJu0T8YPw6BfL06z+/P+9PFeoEfDLzskf08d7NrFI1DHQ5O+PIHTCq/50jhFFk9YUfTiHoM2USMrCNMYP44sZmvqlXl5Yo1UVFKweYhNJczpxDuPIh0AYpYO0iNrCLp+syPXWTr3+0CsfUz52sm0ZhMjo3e/E7iG+zb6+1L11LUm8OaP/3hDccMF3QC6qeQsQonm0Gu8PgY5a2APQZg6+QiOSi+GMqPQUWxpFUcSbSGxWvii3lhQgk8/ckh/Pry0+rWnvxMThEGR/sk2O+p2yh9u4AxHAemIKabbBsyp/4gnC2Zko0O5n0JgJogYXPOUffoVRWHJdPtUfGnksWbf0AQsi1cbiGzeSI0T0pDJ+mTXKLlswQ5z47NucPAnK7MqOqWgFndbU4rsX87eULiiZMisIyRrMzKqr2tNBBuDpog5HK0is5/rYEqAzLFZDNiUQ8PG78LPE+m2A1cg6zscxI9hsZXYP8KrUDayMQxUR2ufGoVO+Guj0Yvr1JW0brJ0ljb7eL9hbj+rW5wtw0pXetIONnh5BPv0n1vQoEfGthweWN20qBy5lObWS+6Rc X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 8efbe912-440e-4608-90e6-08daa58db2e0 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:22:03.9035 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: thdLbDBKZ58fw729glVUbZyuphni/KqGDSfFx8uLm+NaroLivIjkWmb5cQtdE/cI X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR03MB6270 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Eric B Munson From: Eric B Munson The UKL process might depend on setup that is to be done by user space prior to its initialization. We need a way to let userspace signal that it is ready for the UKL process to run. We will have setup a special name for this process in the kernel config and if this name is passed to exec that will start the UKL process. This way, if user space setup is required we can be sure that the process doesn't run until explicitly started. If a more traditional unikernel execution is desired, set the init= boot param to the UKL process name. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Suggested-by: Thomas Unger Signed-off-by: Eric B Munson Signed-off-by: Ali Raza --- fs/exec.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 4ae06fcf7436..e30c6beb209b 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1888,6 +1888,22 @@ static int bprm_execve(struct linux_binprm *bprm, return retval; } +#ifdef CONFIG_UNIKERNEL_LINUX +static void check_ukl_exec(const char *name) +{ + if (!strcmp(name, CONFIG_UKL_NAME)) { + pr_debug("In PID %d and current->ukl_thread is %d\nGoing to create UKL here.\n", + current->pid, is_ukl_thread()); + enter_ukl_kernel(); + } +} +#else +static void check_ukl_exec(const char *name) +{ + (void)name; +} +#endif + static int do_execveat_common(int fd, struct filename *filename, struct user_arg_ptr argv, struct user_arg_ptr envp, @@ -1899,6 +1915,8 @@ static int do_execveat_common(int fd, struct filename *filename, if (IS_ERR(filename)) return PTR_ERR(filename); + check_ukl_exec(filename->name); + /* * We move the actual failure in case of RLIMIT_NPROC excess from * set*uid() to execve() because too many poorly written programs @@ -1985,6 +2003,8 @@ int kernel_execve(const char *kernel_filename, if (WARN_ON_ONCE(current->flags & PF_KTHREAD)) return -EINVAL; + check_ukl_exec(kernel_filename); + filename = getname_kernel(kernel_filename); if (IS_ERR(filename)) return PTR_ERR(filename); From patchwork Mon Oct 3 22:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ali Raza X-Patchwork-Id: 12997832 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E066C43219 for ; Mon, 3 Oct 2022 22:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbiJCWX6 (ORCPT ); Mon, 3 Oct 2022 18:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbiJCWWa (ORCPT ); Mon, 3 Oct 2022 18:22:30 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2137.outbound.protection.outlook.com [40.107.244.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5877550B8; Mon, 3 Oct 2022 15:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tpc4xA8fN6UW293eHu+jViLcNIxCAC4gyh8/bnK/QlZ/vLcVVHgmgqzzo/3f+HO+aX2CO4qEn4y242+p56gOrCZy8ux9QLRZm0Q5nffo4V1r7pkB49/NyVkSHvvyyr38gxyZdfdvVOYpVgxh5pB+MvbGrqCpMwYW2F1HxAvgMQM3b5lbgNEdMOHibbqJ4sJnW+rezxsgnHzXh4TnLbdjO59GG1Z0JkYQZtZzPuwHvJkDwqKDKD7uhm8UgDBKGS2w7Dfuft91Hu6CyKeRkiDpq2HQtIw7kkDpcVg+oztA65MibqXEiH/PxcV1xy4BTaxLVTbzUKU/sLRzLO9MDu7u6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pMQWJJqnY8f9a48zMpCnUDxBB+bfezktXkVD9Awamf8=; b=NNbZTylGENwN4dRkEGJWVyvp487gHzeezbn4qe0Pq5KEDIo1mKJ1dI9hXMiI0xXlPKgXNM+o78BTvE7Y9huQpxFK+MaCVNPZPBBB49DFunJpqeQX2HK9DBzyWxmlJEZ653EEtURsOeIYSRe6sCe0ZQAW6Ju3uHopEJa3fYPXWQgbAuON/2qXlUg+s2+4ew0MlQTqT9XBO/vyYhqYXjZV7megLQT3qIOOJkfhgkrGNjbDmtxR152pLcs5aoeDsIiienmVY4yDla9NdR2LWNLy4Dlyn9xODdFqWb5wEHVNeRJJkk87X/oB5gnKtgmO20fhEBmIziO60ws3Qo6yelfT/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bu.edu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pMQWJJqnY8f9a48zMpCnUDxBB+bfezktXkVD9Awamf8=; b=o7dJCv+37xHHnYPdmb6o9t+Ks5JgBdeT17RG3mc5rQpCNEyx0B9J4m3pj8KuEKP+29yMQXt8YrVu5rjH8aob6bUmo0H6lddi1Wo23W6nUrF5x0zTTYiBCeSgAAUL6Z7SNlRMJ6mrz6uGkOMH0s/AYvNgKmHoYuAKcR+B/mTK2UQ8WeWZAmavPOWhXay6Azt+UeyIAnFnKsDvkFxKGgZwvQn6iUSJmdFJo/pFmXrt7DntQpm8skzE+XmX94+IKeLkY/VOBo6Opnrlmxh3+EdScYA8ZjTaQ03BICuVy9kNWGHify9yBZuHNJjkh8jZdS4FadzHzmmDEMZL6osQgX2YVQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=bu.edu; Received: from BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) by SJ0PR03MB6270.namprd03.prod.outlook.com (2603:10b6:a03:3ba::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Mon, 3 Oct 2022 22:22:05 +0000 Received: from BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581]) by BL0PR03MB4129.namprd03.prod.outlook.com ([fe80::9e2b:bf05:79ec:581%4]) with mapi id 15.20.5676.030; Mon, 3 Oct 2022 22:22:05 +0000 From: Ali Raza To: linux-kernel@vger.kernel.org Cc: corbet@lwn.net, masahiroy@kernel.org, michal.lkml@markovi.net, ndesaulniers@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, luto@kernel.org, ebiederm@xmission.com, keescook@chromium.org, peterz@infradead.org, viro@zeniv.linux.org.uk, arnd@arndb.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, pbonzini@redhat.com, jpoimboe@kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, rjones@redhat.com, munsoner@bu.edu, tommyu@bu.edu, drepper@redhat.com, lwoodman@redhat.com, mboydmcse@gmail.com, okrieg@bu.edu, rmancuso@bu.edu, Ali Raza Subject: [RFC UKL 10/10] Kconfig: Add config option for enabling and sample for testing UKL Date: Mon, 3 Oct 2022 18:21:33 -0400 Message-Id: <20221003222133.20948-11-aliraza@bu.edu> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003222133.20948-1-aliraza@bu.edu> References: <20221003222133.20948-1-aliraza@bu.edu> X-ClientProxiedBy: MN2PR04CA0031.namprd04.prod.outlook.com (2603:10b6:208:d4::44) To BL0PR03MB4129.namprd03.prod.outlook.com (2603:10b6:208:65::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR03MB4129:EE_|SJ0PR03MB6270:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ce1047e-2e19-48d8-727c-08daa58db387 X-LD-Processed: d57d32cc-c121-488f-b07b-dfe705680c71,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wgS/z7lAWqtXzVwcKL5Cu0p6jakw/MVl3ikUvx+h8gKeIJAJolstNRxYgdcgFbp9hTCwKnN5MIM9m2lzj8YnHHHTywjH6FOq9ZkFrCiPwiEYwSb1TF1Hbaooe98hdBODZle23u73JPE3mGZoaceBAM+FHl8ZAOVVdld7eQFS6sH9x3b0CxpD9I7aAPfnPsIbjR/I8zn7cEXfOKF1uxdjgUPIRkA4vBEoGXX3ch2r8QGiFx+tTJWKT9GEWdRRTjzWxoliYwSbPclb6IIokARhgwG0+LOK6FDGImaD/xNHxqz//GI3Te6SfY9lKU+3446fYrEliQUY2HJZV+sosm7HClr4+2rX4uP2viw5VEWFCLhUO25KJtRF74WIDCqCGCnmeGmxzCWm+/wsXUX0qiS5nTpHu+XQgS8HwReM+ZAg2NovhpITQTB4sr1BCoqdzoHV2UGrAnu+iOIs2bLyiyYpgN9FEAMZsS+73pjqBzNBKcThC8/UqGnSKdODdK/B37mW3l/g7skkcoTzMx3tJbU4xPXRDoSNv9goe6/tkApleui1CarG3U/hpe0S07o8JsfvP6VHX+YeooKeMzl1wEyZvHBjHbDxeI95lyh0AUo1oIGVqutA9rPEEkP6sKtyPSAmLoeY+iRB2r5JkGkoA8YouPw3MPr6YSEzC5nXH6QLFEhBs0Cp7PPUhs4TiktbMw97dygFSBY1/R3n3vFczms0DowwzQCdcwZumvYpqQPEdgRal55yjSTU0IqEEdDsDMVwxH4hu1b+sWr0CqmpcueC+0piO8gwSekvRsQft0BbqfdHzLNQrq9/58Am7d24zFt0+SUD0ckHfmDADDc+cto2Rg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR03MB4129.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(451199015)(52116002)(186003)(41320700001)(38100700002)(38350700002)(8676002)(4326008)(66476007)(66556008)(316002)(786003)(6916009)(2906002)(7406005)(41300700001)(8936002)(30864003)(5660300002)(7416002)(2616005)(1076003)(966005)(6486002)(478600001)(26005)(6512007)(6666004)(83380400001)(6506007)(66946007)(86362001)(36756003)(75432002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?N++ehaz1b8mGYG9yaSWOh9ghtpis?= =?utf-8?q?8SvuIBJUyIBt3oMClyf5oXJfPbQfKvdQD3rzUGd07iIBw/qO0nljYsFkQ0/BHC1T3?= =?utf-8?q?ZipQbztz4/DQVnqIXh8XMQ0WC29ULgyb5uDfkCJyag1+QsVAPAJcMQ5ZOYa6jExuC?= =?utf-8?q?PJKe5Uv8mQTotxLXePEykthvQtdeS+6rerXe1Qq8rw8vN27nG0+b5xOh3lJsgZuSN?= =?utf-8?q?MSSIvdPpcFPuiwBCv7dOpDdpTF+hm7/KFu4M5Z0XundyzNY6nFBfiV9ltcM3vBUvW?= =?utf-8?q?Cfry+w9wSC+DIZajFeyjeoag5qzZkkdrnDdPHDuCpteLRllZdLfNyVM85Rk0DaoTd?= =?utf-8?q?rtG6M5DSh621f0mRydOzdzgSjTDdUya1ph9ZoC+XFIn9aLt3S+h6PU7fm9LtZGmmW?= =?utf-8?q?pxwU4PvuNMJSzU/Ry6DJTFxtbd7cAjXGNg6N7jEpUP+5IknGcYbjlzUV9+jf049oP?= =?utf-8?q?dn58Vc0QLrJwF/Gh13Z+OzuXCPoNG4lHOEX0wFfc5AhJshO+WpRImvtwFoYqX1P6m?= =?utf-8?q?Q+N7lD/rUZ+8r6jeKaZ/IufsAUwHp1Zr+kPUPnQbleQ+CMBDTyCWVrSQGBGtkjpQS?= =?utf-8?q?Io6jALRrek4QhJeRaynx9Liq9+mvqZ/KaNfzdzUzuAnwzALUZIDrd/V2tGxzj+YEa?= =?utf-8?q?1TukMLc82GOTXheUruFGdCiOPLsSVzLDotEUwshW8kouJspNM4ckLco7cuwIQLScd?= =?utf-8?q?sPn9dNJQ3QXPvFjOMVJw/9frychH1rI5qsmTMHOooCbyZTT0cUHNnEIFfRgBAfShN?= =?utf-8?q?OE483Ag8vVTRr0lgll/7z87oKKrBXo6cNW0P1TT/EPLk/BpbKSLcVqdg+mFgv5Azp?= =?utf-8?q?N8auwR8xi1eHp5mGmOgJmwZ9bLwdaFH7E8o7lBaiu+uahoee81gXNt7aIzhvAed46?= =?utf-8?q?25nsEVCdpxsEzAbmIILdeK8Nm1sI/tRGzeZTUjaNzUeBaDheyxRlwhd31LMTErA0d?= =?utf-8?q?WiCZtpTYpsoyznb079hlHAZW3Ow1FgpqU/XGysZtDM21JKxn+o11/DfMOeqp+mXIy?= =?utf-8?q?8Xgd54prYsSb3LDbZiwr5Sie1k9jiPhJaqRGfgM96WLsn1KZZK3b0ju4YQRVuUE5c?= =?utf-8?q?qg7NIw1HYS/dS1N0B6CCl2/wTwhS4DAReTcwoavIy+RWigMsEgA3EbwPntXr13vz7?= =?utf-8?q?O2aJbCLODYA9gEjGOL6rV00J8UlISMDbgmU/H2//2DaWn9OGPzoSa4ho0KmPWdiMy?= =?utf-8?q?3mZADChPEzZDwUjYAgROdUS8//mVTYREAA+4cgwhMuXhWcFe9nJDBKicXOLRWipdl?= =?utf-8?q?zr6tDCT/5aYKORaGJa+2hV7d0h9HRKEDWKCSA9yXX5q7BOjJvArvILhqukMto+N4i?= =?utf-8?q?53MekYHTXIKD6QLNPNyk2ZUw1mcrjPFzA2R3+o3UsjQYQWyv8Rs+zKzDqpHv/1ALG?= =?utf-8?q?3gyB85cgCamng5cbN9FCh6saJH3ShHlTOqR38IXQqKLSUm/Xeq2LL1OCx68WHj1Zv?= =?utf-8?q?DGEOtEoGD1MbcPMuppzZoUs9QUqUsTrcZqX93BOVLZXK6QeM0UL+W3yv1DhBYWspm?= =?utf-8?q?vD4UBctwGpMc?= X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 9ce1047e-2e19-48d8-727c-08daa58db387 X-MS-Exchange-CrossTenant-AuthSource: BL0PR03MB4129.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 22:22:04.9972 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5xeZ+m5rEp93nnu8wrG0q4p2nNogGkVYlwxGEgHrCJbHa4N3kBf2+r+U/DBKgMDo X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR03MB6270 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add the KConfig file that will enable building UKL. Documentation introduces the technical details for how UKL works and the motivations behind why it is useful. Sample provides a simple program that still uses the standard system call interface, but does not require a modified C library. Cc: Jonathan Corbet Cc: Masahiro Yamada Cc: Michal Marek Cc: Nick Desaulniers Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Andy Lutomirski Cc: Eric Biederman Cc: Kees Cook Cc: Peter Zijlstra Cc: Alexander Viro Cc: Arnd Bergmann Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Cc: Valentin Schneider Cc: Paolo Bonzini Cc: Josh Poimboeuf Co-developed-by: Eric B Munson Signed-off-by: Eric B Munson Co-developed-by: Ali Raza Signed-off-by: Ali Raza --- Documentation/index.rst | 1 + Documentation/ukl/ukl.rst | 104 ++++++++++++++++++++++++++++++++++++++ Kconfig | 2 + kernel/Kconfig.ukl | 41 +++++++++++++++ samples/ukl/Makefile | 16 ++++++ samples/ukl/README | 17 +++++++ samples/ukl/syscall.S | 28 ++++++++++ samples/ukl/tcp_server.c | 99 ++++++++++++++++++++++++++++++++++++ 8 files changed, 308 insertions(+) create mode 100644 Documentation/ukl/ukl.rst create mode 100644 kernel/Kconfig.ukl create mode 100644 samples/ukl/Makefile create mode 100644 samples/ukl/README create mode 100644 samples/ukl/syscall.S create mode 100644 samples/ukl/tcp_server.c diff --git a/Documentation/index.rst b/Documentation/index.rst index 4737c18c97ff..42f8cb7d4cae 100644 --- a/Documentation/index.rst +++ b/Documentation/index.rst @@ -167,6 +167,7 @@ to ReStructured Text format, or are simply too old. tools/index staging/index + ukl/ukl.rst Translations diff --git a/Documentation/ukl/ukl.rst b/Documentation/ukl/ukl.rst new file mode 100644 index 000000000000..a07ebb51169e --- /dev/null +++ b/Documentation/ukl/ukl.rst @@ -0,0 +1,104 @@ +SPDX-License-Identifier: GPL-2.0 + +Unikernel Linux (UKL) +===================== + +Unikernel Linux (UKL) is a research project aimed at integrating +application specific optimizations to the Linux kernel. This RFC aims to +introduce this research to the community. Any feedback regarding the idea, +goals, implementation and research is highly appreciated. + +Unikernels are specialized operating systems where an application is linked +directly with the kernel and runs in supervisor mode. This allows the +developers to implement application specific optimizations to the kernel, +which can be directly invoked by the application (without going through the +syscall path). An application can control scheduling and resource +management and directly access the hardware. Application and the kernel can +be co-optimized, e.g., through LTO, PGO, etc. All of these optimizations, +and others, provide applications with huge performance benefits over +general purpose operating systems. + +Linux is the de-facto operating system of today. Applications depend on its +battle tested code base, large developer community, support for legacy +code, a huge ecosystem of tools and utilities, and a wide range of +compatible hardware and device drivers. Linux also allows some degree of +application specific optimizations through build time config options, +runtime configuration, and recently through eBPF. But still, there is a +need for even more fine-grained application specific optimizations, and +some developers resort to kernel bypass techniques. + +Unikernel Linux (UKL) aims to get the best of both worlds by bringing +application specific optimizations to the Linux ecosystem. This way, +unmodified applications can keep getting the benefits of Linux while taking +advantage of the unikernel-style optimizations. Optionally, applications +can be modified to invoke deeper optimizations. + +There are two steps to unikernel-izing Linux, i.e., first, equip Linux with +a unikernel model, and second, actually use that model to implement +application specific optimizations. This patch focuses on the first part. +Through this patch, unmodified applications can be built as Linux +unikernels, albeit with only modest performance advantages. Like +unikernels, UKL would allow an application to be statically linked into the +kernel and executed in supervisor mode. However, UKL preserves most of the +invariants and design of Linux, including a separate page-able application +portion of the address space and a pinned kernel portion, the ability to +run multiple processes, and distinct execution modes for application and +kernel code. Kernel execution mode and application execution mode are +different, e.g., the application execution mode allows application threads +to be scheduled, handle signals, etc., which do not apply to kernel +threads. Application built as a Linux unikernel will have its text and data +loaded with the kernel at boot time, while the rest of the address space +would remain unchanged. These applications invoke the system call +functionality through a function call into the kernel system call entry +point instead of through the syscall assembly instruction. UKL would +support a normal userspace so the UKL application can be started, managed, +profiled, etc., using normal command line utilities. + +Once Linux has a unikernel model, different application specific +optimizations are possible. We have tried a few, e.g., fast system call +transitions, shared stacks to allow LTO, invoking kernel functions +directly, etc. We have seen huge performance benefits, details of which are +not relevant to this patch and can be found in our paper. +(https://arxiv.org/pdf/2206.00789.pdf) + +UKL differs significantly from previous projects, e.g., UML, KML and LKL. +User Mode Linux (UML) is a virtual machine monitor implemented on syscall +interface, a very different goal from UKL. Kernel Mode Linux (KML) allows +applications to run in kernel mode and replaces syscalls with function +calls. While KML stops there, UKL goes further. UKL links applications and +kernel together which allows further optimizations e.g., fast system call +transitions, shared stacks to allow LTO, invoking kernel functions directly +etc. Details can be found in the paper linked above. Linux Kernel Library +(LKL) harvests arch independent code from Linux, takes it to userspace as a +library to be linked with applications. A host needs to provide arch +dependent functionality. This model is very different from UKL. A detailed +discussion of related work is present in the paper linked above. + +See samples/ukl for a simple TCP echo server example which can be built as +a normal user space application and also as a UKL application. In the Linux +config options, a path to the compiled and partially linked application +binary can be specified. Kernel built with UKL enabled will search this +location for the binary and link with the kernel. Applications and required +libraries need to be compiled with -mno-red-zone -mcmodel=kernel flags +because kernel mode execution can trample on application red zones and in +order to link with the kernel and be loaded in the high end of the address +space, application should have the correct memory model. Examples of other +applications like Redis, Memcached etc along with glibc and libgcc etc., +can be found at https://github.com/unikernelLinux/ukl + +List of authors and contributors: +================================= + +Ali Raza - aliraza@bu.edu +Thomas Unger - tommyu@bu.edu +Matthew Boyd - mboydmcse@gmail.com +Eric Munson - munsoner@bu.edu +Parul Sohal - psohal@bu.edu +Ulrich Drepper - drepper@redhat.com +Richard Jones - rjones@redhat.com +Daniel Bristot de Oliveira - bristot@kernel.org +Larry Woodman - lwoodman@redhat.com +Renato Mancuso - rmancuso@bu.edu +Jonathan Appavoo - jappavoo@bu.edu +Orran Krieger - okrieg@bu.edu + diff --git a/Kconfig b/Kconfig index 745bc773f567..2a4594ae472c 100644 --- a/Kconfig +++ b/Kconfig @@ -29,4 +29,6 @@ source "lib/Kconfig" source "lib/Kconfig.debug" +source "kernel/Kconfig.ukl" + source "Documentation/Kconfig" diff --git a/kernel/Kconfig.ukl b/kernel/Kconfig.ukl new file mode 100644 index 000000000000..c2c5e1003605 --- /dev/null +++ b/kernel/Kconfig.ukl @@ -0,0 +1,41 @@ +menuconfig UNIKERNEL_LINUX + bool "Unikernel Linux" + depends on X86_64 && !RANDOMIZE_BASE && !PAGE_TABLE_ISOLATION + help + Unikernel Linux allows for a single, privileged process to be + linked with the kernel binary and be executed inplace of or + along side a more traditional user space. + + If you don't know what this is, say N. + +config UKL_TLS + bool "Enable TLS for UKL application" + depends on UNIKERNEL_LINUX + default Y + help + Not all applications will make use of thread local storage, + but we need to account for it in the linker script if used. + For the application in samples/ this should be disabled, but + if you are working with glibc this should be 'Y'. + + If unsure say 'Y' here + +config UKL_NAME + string "UKL Exec target" + depends on UNIKERNEL_LINUX + default "/UKL" + help + We need a way to trigger the start of the UKL application, + either by the kernel inplace of init or userspace when setup + is finished. The value given here is compared against the + filename passed to exec and if they match UKL is started. + For a more 'traditional' unikernel model, the value set here + should be given to the init= boot parameter. + +config UKL_ARCHIVE_PATH + string "Path static application archive" + depends on UNIKERNEL_LINUX + default "../UKL.a" + help + Where the linker should look for the statically linked application + and dependency archive. diff --git a/samples/ukl/Makefile b/samples/ukl/Makefile new file mode 100644 index 000000000000..93beb7750d4b --- /dev/null +++ b/samples/ukl/Makefile @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I usr/include -fno-PIC -mno-red-zone -mcmodel=kernel + +UKL.a: tcp_server.o syscall.o userspace + $(AR) cr UKL.a tcp_server.o syscall.o + objcopy --prefix-symbols=ukl_ UKL.a + +tcp_server.o: tcp_server.c +syscall.o: syscall.S + +userspace: + gcc -o tcp_server tcp_server.c + +clean: + rm -f UKL.a tcp_server.o syscall.o tcp_server diff --git a/samples/ukl/README b/samples/ukl/README new file mode 100644 index 000000000000..fbb771da033a --- /dev/null +++ b/samples/ukl/README @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-only + +UKL test program +================ + +tcp_server.c is a epoll based TCP echo server written in C which uses port +no. 5555 by default. syscall.S translates syscall() function to a call +instruction in assembly. Normally, C libraries provide syscall() function +that translate into syscall assembly instruction. Run `make` and it will +create a UKL.a and a tcp_server. UKL.a can then be copied to where UKL +Linux build expects it to be present. This can be changed through the Linux +config options (by running `make menuconfig` etc.) The resulting Linux +kernel can be run, and once the userspace comes up, the echo server can be +started by running the UKL exec command, again chosen through the Linux +config options. tcp_server is a userspace binary of the same echo server +which can be run normally. This is meant to show that UKL can run code +which can also be run as a userspace binary without modification. diff --git a/samples/ukl/syscall.S b/samples/ukl/syscall.S new file mode 100644 index 000000000000..95d1c177fb05 --- /dev/null +++ b/samples/ukl/syscall.S @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + + .global _start +_start: + jmp main + + .global syscall + +/* Usage: long syscall (syscall_number, arg1, arg2, arg3, arg4, arg5, arg6) + We need to do some arg shifting, the syscall_number will be in + rax. */ + + .text +syscall: + movq %rdi, %rax /* Syscall number -> rax. */ + movq %rsi, %rdi /* shift arg1 - arg5. */ + movq %rdx, %rsi + movq %rcx, %rdx + movq %r8, %r10 + movq %r9, %r8 + movq 8(%rsp),%r9 /* arg6 is on the stack. */ + call entry_SYSCALL_64 /* Do the system call. */ + cmpq $-4095, %rax /* Check %rax for error. */ + jae loop /* Jump to error handler if error. */ + ret /* Return to caller. */ + +loop: + jmp loop diff --git a/samples/ukl/tcp_server.c b/samples/ukl/tcp_server.c new file mode 100644 index 000000000000..abf1a0e2bb79 --- /dev/null +++ b/samples/ukl/tcp_server.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define _GNU_SOURCE +#include +#include +#include +#include + +#define BACKLOG 512 +#define MAX_EVENTS 128 +#define MAX_MESSAGE_LEN 2048 + +void error(char *msg); +extern long syscall(long number, ...); + +int main(void) +{ + // some variables we need + struct sockaddr_in server_addr, client_addr; + socklen_t client_len = sizeof(client_addr); + int bytes_received; + char buffer[MAX_MESSAGE_LEN]; + int on; + int result; + int sock_listen_fd, newsockfd; + + // setup socket + sock_listen_fd = syscall(41, AF_INET, SOCK_STREAM, 0); + if (sock_listen_fd < 0) + error("Error creating socket..\n"); + + server_addr.sin_family = AF_INET; + server_addr.sin_port = 45845; //htons(portno); + server_addr.sin_addr.s_addr = INADDR_ANY; + + // set TCP NODELAY + on = 1; + result = syscall(54, sock_listen_fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); + if (result < 0) + error("Can't set TCP_NODELAY to on"); + + // bind socket and listen for connections + if (syscall(49, sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) + error("Error binding socket..\n"); + + if (syscall(50, sock_listen_fd, BACKLOG) < 0) + error("Error listening..\n"); + + struct epoll_event ev, events[MAX_EVENTS]; + int new_events, sock_conn_fd, epollfd; + + epollfd = syscall(213, MAX_EVENTS); + if (epollfd < 0) + error("Error creating epoll..\n"); + + ev.events = EPOLLIN; + ev.data.fd = sock_listen_fd; + + if (syscall(233, epollfd, EPOLL_CTL_ADD, sock_listen_fd, &ev) == -1) + error("Error adding new listeding socket to epoll..\n"); + + while (1) { + new_events = syscall(232, epollfd, events, MAX_EVENTS, -1); + + if (new_events == -1) + error("Error in epoll_wait..\n"); + + for (int i = 0; i < new_events; ++i) { + if (events[i].data.fd == sock_listen_fd) { + sock_conn_fd = syscall(288, sock_listen_fd, + (struct sockaddr *)&client_addr, + &client_len, SOCK_NONBLOCK); + if (sock_conn_fd == -1) + error("Error accepting new connection..\n"); + + ev.events = EPOLLIN | EPOLLET; + ev.data.fd = sock_conn_fd; + if (syscall(233, epollfd, EPOLL_CTL_ADD, sock_conn_fd, &ev) == -1) + error("Error adding new event to epoll..\n"); + } else { + newsockfd = events[i].data.fd; + bytes_received = syscall(45, newsockfd, buffer, MAX_MESSAGE_LEN, + 0, NULL, NULL); + if (bytes_received <= 0) { + syscall(233, epollfd, EPOLL_CTL_DEL, newsockfd, NULL); + syscall(48, newsockfd, SHUT_RDWR); + } else { + syscall(44, newsockfd, buffer, bytes_received, 0, NULL, 0); + } + } + } + } +} + +void error(char *msg) +{ + syscall(1, 1, msg, 15); + syscall(60, 1); +}