From patchwork Thu Feb 25 07:29:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12103559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AFBFC433E6 for ; Thu, 25 Feb 2021 07:33:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 91A9764E90 for ; Thu, 25 Feb 2021 07:33:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 91A9764E90 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3528C8D0001; Thu, 25 Feb 2021 02:33:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DE556B0074; Thu, 25 Feb 2021 02:33:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 157A88D0001; Thu, 25 Feb 2021 02:33:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0155.hostedemail.com [216.40.44.155]) by kanga.kvack.org (Postfix) with ESMTP id F1B176B0073 for ; Thu, 25 Feb 2021 02:33:52 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C4F85180AC498 for ; Thu, 25 Feb 2021 07:33:52 +0000 (UTC) X-FDA: 77855975904.24.97DE335 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf24.hostedemail.com (Postfix) with ESMTP id BAC81A0009D1 for ; Thu, 25 Feb 2021 07:33:46 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id l2so3244369pgb.1 for ; Wed, 24 Feb 2021 23:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5ebRx4V31DSDhZXC0yr3LtKn279spf6opfPxtzn4I70=; b=b5Dg9LmaXf2YzgQNvM6K47rUortYW8n2hCPF5Krke30h9MXYtgfvQkBUZygduBw47k HOWRlBh3NPu3jRaUUgDwM9zK0n/HsCOVwYAsKiE+4GeDc0kfUqYBXSmbMPoMEeKO9L3r lUuUSKzR6/htE7vhh8dSgrr43yqm4IczLlTppo3nunX/DE0c9gLZuDIVFcjvFyUW8+27 UEME7RkgvXelyfL29k8zxAgPBQJnWM0zXlTCt8Tt3rEspcDcVntrYmHTCnLVYg1OX/k3 UeoXLbqXEl7oOYwyS1AseioOuPsNagDFOdNvUIkbWVYr9bhFwcyDy0qbjZqtZ0MWwKxl RA8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5ebRx4V31DSDhZXC0yr3LtKn279spf6opfPxtzn4I70=; b=NlKv2sEZuIvb145EYg2oVTnQLHBar1if71rho8VOR6iaMDJfWzz1iHvrFMIoSu26rh 1O2yCjjn9JmVgIwNRvfSfgAFUsWGV79IUsB92kcpdjvEjrZ6KLgH6509LZK/OMWqAQp0 WmlOS9B+Es+9D4Otvkj3g3ZKRH4sX2y6iA6BLso/FnDY3gsvAVwBE5wdLL8K2lPVpikk pFvJj9DsVt+qp05Q8wdwJD7ZMs7u34lFRAA5nM81eZPUx7lUZjtaI2rL4iIG6s8aw1L+ DR61sK1oAYknPx8o23EI3UUAqP8ZUw8Dk/m7037xVl4hu1v+19d4Hkk/a9hihWCXM+WC h48A== X-Gm-Message-State: AOAM530evFn3XJSo2x0qZl0fQn3WrnKnmMGZGHGnrpnR2tc7nvg5lpD8 onHcifr6ASIrcL/DelUeRXmouE0/2bTgcw== X-Google-Smtp-Source: ABdhPJz45/nZGq0qVdXrll6ISaRWXK4Er9JRFHjpVmUudiHHnAwEcTD+fJdDZQNzJuCCFu58chwvew== X-Received: by 2002:a05:6a00:22d1:b029:1b4:9bb5:724c with SMTP id f17-20020a056a0022d1b02901b49bb5724cmr2069327pfj.63.1614238430691; Wed, 24 Feb 2021 23:33:50 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id w3sm4917561pjt.24.2021.02.24.23.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 23:33:50 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Andy Lutomirski , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Borislav Petkov , Nadav Amit , Sean Christopherson , Andrew Morton , x86@kernel.org Subject: [RFC 2/6] x86/vdso: add mask and flags to extable Date: Wed, 24 Feb 2021 23:29:06 -0800 Message-Id: <20210225072910.2811795-3-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210225072910.2811795-1-namit@vmware.com> References: <20210225072910.2811795-1-namit@vmware.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: BAC81A0009D1 X-Stat-Signature: fw81q8bkkpkwwo7j4cjupxhu8yn1ebpi Received-SPF: none (<>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from="<>"; helo=mail-pg1-f182.google.com; client-ip=209.85.215.182 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614238426-643960 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Nadav Amit Add a "mask" field to vDSO exception tables that says which exceptions should be handled. Add a "flags" field to vDSO as well to provide additional information about the exception. The existing preprocessor macro _ASM_VDSO_EXTABLE_HANDLE for assembly is not easy to use as it requires the user to stringify the expanded C macro. Remove _ASM_VDSO_EXTABLE_HANDLE and use a similar scheme to ALTERNATIVE, using assembly macros directly in assembly without wrapping them in C macros. Move the vsgx supported exceptions test out of the generic C code into vsgx-specific assembly by setting vsgx supported exceptions in the mask. Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Sean Christopherson Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Andrew Morton Cc: x86@kernel.org Signed-off-by: Nadav Amit --- arch/x86/entry/vdso/extable.c | 9 +-------- arch/x86/entry/vdso/extable.h | 21 +++++++++++++-------- arch/x86/entry/vdso/vsgx.S | 9 +++++++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/arch/x86/entry/vdso/extable.c b/arch/x86/entry/vdso/extable.c index c81e78636220..93fb37bd32ad 100644 --- a/arch/x86/entry/vdso/extable.c +++ b/arch/x86/entry/vdso/extable.c @@ -7,6 +7,7 @@ struct vdso_exception_table_entry { int insn, fixup; + unsigned int mask, flags; }; bool fixup_vdso_exception(struct pt_regs *regs, int trapnr, @@ -17,14 +18,6 @@ bool fixup_vdso_exception(struct pt_regs *regs, int trapnr, unsigned int nr_entries, i; unsigned long base; - /* - * Do not attempt to fixup #DB or #BP. It's impossible to identify - * whether or not a #DB/#BP originated from within an SGX enclave and - * SGX enclaves are currently the only use case for vDSO fixup. - */ - if (trapnr == X86_TRAP_DB || trapnr == X86_TRAP_BP) - return false; - if (!current->mm->context.vdso) return false; diff --git a/arch/x86/entry/vdso/extable.h b/arch/x86/entry/vdso/extable.h index b56f6b012941..7ca8a0776805 100644 --- a/arch/x86/entry/vdso/extable.h +++ b/arch/x86/entry/vdso/extable.h @@ -2,26 +2,31 @@ #ifndef __VDSO_EXTABLE_H #define __VDSO_EXTABLE_H +#include + +#define ASM_VDSO_ASYNC_FLAGS (1 << 0) + /* * Inject exception fixup for vDSO code. Unlike normal exception fixup, * vDSO uses a dedicated handler the addresses are relative to the overall * exception table, not each individual entry. */ #ifdef __ASSEMBLY__ -#define _ASM_VDSO_EXTABLE_HANDLE(from, to) \ - ASM_VDSO_EXTABLE_HANDLE from to - -.macro ASM_VDSO_EXTABLE_HANDLE from:req to:req +.macro ASM_VDSO_EXTABLE_HANDLE from:req to:req mask:req flags:req .pushsection __ex_table, "a" .long (\from) - __ex_table .long (\to) - __ex_table + .long (\mask) + .long (\flags) .popsection .endm #else -#define _ASM_VDSO_EXTABLE_HANDLE(from, to) \ - ".pushsection __ex_table, \"a\"\n" \ - ".long (" #from ") - __ex_table\n" \ - ".long (" #to ") - __ex_table\n" \ +#define ASM_VDSO_EXTABLE_HANDLE(from, to, mask, flags) \ + ".pushsection __ex_table, \"a\"\n" \ + ".long (" #from ") - __ex_table\n" \ + ".long (" #to ") - __ex_table\n" \ + ".long (" #mask ")\n" \ + ".long (" #flags ")\n" \ ".popsection\n" #endif diff --git a/arch/x86/entry/vdso/vsgx.S b/arch/x86/entry/vdso/vsgx.S index 86a0e94f68df..c588255af480 100644 --- a/arch/x86/entry/vdso/vsgx.S +++ b/arch/x86/entry/vdso/vsgx.S @@ -4,6 +4,7 @@ #include #include #include +#include #include "extable.h" @@ -146,6 +147,10 @@ SYM_FUNC_START(__vdso_sgx_enter_enclave) .cfi_endproc -_ASM_VDSO_EXTABLE_HANDLE(.Lenclu_eenter_eresume, .Lhandle_exception) - +/* + * Do not attempt to fixup #DB or #BP. It's impossible to identify + * whether or not a #DB/#BP originated from within an SGX enclave. + */ +ASM_VDSO_EXTABLE_HANDLE .Lenclu_eenter_eresume, .Lhandle_exception, \ + ~((1<