From patchwork Tue Oct 16 23:50:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Higgins X-Patchwork-Id: 10644367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 452F513AD for ; Tue, 16 Oct 2018 23:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35F9529124 for ; Tue, 16 Oct 2018 23:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A5292A27D; Tue, 16 Oct 2018 23:54:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2A8E29124 for ; Tue, 16 Oct 2018 23:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727526AbeJQHqz (ORCPT ); Wed, 17 Oct 2018 03:46:55 -0400 Received: from mail-vk1-f201.google.com ([209.85.221.201]:34471 "EHLO mail-vk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727549AbeJQHqz (ORCPT ); Wed, 17 Oct 2018 03:46:55 -0400 Received: by mail-vk1-f201.google.com with SMTP id r75-v6so7019540vkr.1 for ; Tue, 16 Oct 2018 16:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QsZ3was/QkGUo6BYsP86tczumclzu/oVJ8cXDvZ38AM=; b=YPx2z2OGVftv8Dgf9hsP/BheUOYZFFBIJGxjmrXiQJYj4a1tn1kaNN09vpi1NKcpm2 JAZ8twZJiDMzSLhE+Mh397wmrl9kofyv/dOYsA4HBUqYXjYVAc0ZT6pON/EHIJaYUT2B 9jwfmA2gJxOXt1amkDD6rO+kaCLxft4cJg2eyLovzY/K0a7FvFC2VmYJ/IRq8ioWyYER G+9z/EDxYQMHTe5+Ld4lCNch12O10HzHmHkaRi5j/bLIhl/lKlSYzqW2f10LyWJ4n3XD Uvj/JkYva3y5wiRudK4WLtPONTRM51xi4AMDENu5RyPMsKIxm3H8Dn2ACpQ9JTB3V+wW iB7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QsZ3was/QkGUo6BYsP86tczumclzu/oVJ8cXDvZ38AM=; b=GGXVTXfq60eJwDL/+d1jA4FhqWDV3444ZM7qwngbX1WatGCo0pttQU730MmdnO1UJx +zdKB9WLxNrSgFh/UJjkN9jb8kOycFAdqjN9EDVApqi5m3llYmW/Wf9vpiXFX27rVKde 6NqR4iDp4+ZWFjXqoAjwhxfimOd1welZC6xMbkgbwL+b3+SQZhKEl4Yu/Oh3PTpbBOfB IId8Fpa+7o4de0YAuxUcLgZUne9IOUj6i6NdEejh/OQu99JMKEb7rQkw6NY7vUnXj/ch wEBlFCehPKwNpaCwJzto1GbfKevpGygy9wzc8ZPkgT0cH03PxLuw+U2IeybWJL7pQcH1 e3LQ== X-Gm-Message-State: ABuFfoh69Tl8RvVE7yBDI0coq4ewU9gTmgiof5ER/v45+gYSH3QGnN+g bgZWIYg5oVYKLSsQU5bJa2BkytiITBm38yUIpz4cHQ== X-Google-Smtp-Source: ACcGV60TLAfJsKdTy2qQsKGEQgz5iDLsnZOMXyseSry9uD/hbZHFRPqzws3bKPdJyVvsNAbfBdbXDALvGPxOk4AAqTFd0g== X-Received: by 2002:a67:4551:: with SMTP id s78mr23044696vsa.12.1539734046197; Tue, 16 Oct 2018 16:54:06 -0700 (PDT) Date: Tue, 16 Oct 2018 16:50:57 -0700 In-Reply-To: <20181016235120.138227-1-brendanhiggins@google.com> Message-Id: <20181016235120.138227-9-brendanhiggins@google.com> Mime-Version: 1.0 References: <20181016235120.138227-1-brendanhiggins@google.com> X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog Subject: [RFC v1 08/31] arch: um: added shim to trap to allow installing a fault catcher for tests From: Brendan Higgins To: gregkh@linuxfoundation.org, keescook@google.com, mcgrof@kernel.org, shuah@kernel.org Cc: joel@jms.id.au, mpe@ellerman.id.au, joe@perches.com, brakmo@fb.com, rostedt@goodmis.org, Tim.Bird@sony.com, khilman@baylibre.com, julia.lawall@lip6.fr, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, jdike@addtoit.com, richard@nod.at, linux-um@lists.infradead.org, Brendan Higgins Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Added context to current thread that allows a test to specify that it wants to skip the normal checks to run an installed fault catcher. Signed-off-by: Brendan Higgins --- arch/um/include/asm/processor-generic.h | 4 +++- arch/um/kernel/trap.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/um/include/asm/processor-generic.h b/arch/um/include/asm/processor-generic.h index b58b746d3f2ca..d566cd416ff02 100644 --- a/arch/um/include/asm/processor-generic.h +++ b/arch/um/include/asm/processor-generic.h @@ -27,6 +27,7 @@ struct thread_struct { struct task_struct *prev_sched; struct arch_thread arch; jmp_buf switch_buf; + bool is_running_test; struct { int op; union { @@ -51,7 +52,8 @@ struct thread_struct { .fault_addr = NULL, \ .prev_sched = NULL, \ .arch = INIT_ARCH_THREAD, \ - .request = { 0 } \ + .request = { 0 }, \ + .is_running_test = false, \ } static inline void release_thread(struct task_struct *task) diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c index ec9a42c14c565..9b97712daf14f 100644 --- a/arch/um/kernel/trap.c +++ b/arch/um/kernel/trap.c @@ -201,6 +201,12 @@ void segv_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs) segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs); } +static void segv_run_catcher(jmp_buf *catcher, void *fault_addr) +{ + current->thread.fault_addr = fault_addr; + UML_LONGJMP(catcher, 1); +} + /* * We give a *copy* of the faultinfo in the regs to segv. * This must be done, since nesting SEGVs could overwrite @@ -219,7 +225,10 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, if (!is_user && regs) current->thread.segv_regs = container_of(regs, struct pt_regs, regs); - if (!is_user && (address >= start_vm) && (address < end_vm)) { + catcher = current->thread.fault_catcher; + if (catcher && current->thread.is_running_test) + segv_run_catcher(catcher, (void *) address); + else if (!is_user && (address >= start_vm) && (address < end_vm)) { flush_tlb_kernel_vm(); goto out; } @@ -246,12 +255,10 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, address = 0; } - catcher = current->thread.fault_catcher; if (!err) goto out; else if (catcher != NULL) { - current->thread.fault_addr = (void *) address; - UML_LONGJMP(catcher, 1); + segv_run_catcher(catcher, (void *) address); } else if (current->thread.fault_addr != NULL) panic("fault_addr set but no fault catcher");