Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp521403pxf; Wed, 10 Mar 2021 10:53:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+WR5OTDxkZEDNVVRCGlUit1nFxBt54jLTwI9ri4CnurUKSVHETZtSCGzq1ttkxwDPFLHV X-Received: by 2002:a50:ef11:: with SMTP id m17mr4858139eds.151.1615402429439; Wed, 10 Mar 2021 10:53:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615402429; cv=none; d=google.com; s=arc-20160816; b=ViAt8UW2dCPJzvaz1fQArsutjw2hoTpMqq5FtXFouL0ThLz1EyWghIobBToNhuG7EV 6Sb18CY4j1lKFiuBx4MJaChZ6bO17cPbwz7WpH+nZPOL/UrYKjXsvtEhIj7Rrfe4q79R P+LkD84ahmw+McF51FpJN1iwYoP19XpXS+d3jnjU2XxBhMn5KhBF9BvMa3w8foMgYyeA FVS9U+ccP/CxvjCwoquggr65zdzP/whAzGQBCxkGP2MsHHGhWfzavmAUA4oHPwwl3j1P Gsh/6odPpt4GdaJ/fWgv4Mmwg/klEaldfhGTjs9AJUIDiiN19wZlzAGd2Ga2YvsCJAvV 7IFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ujgHC2APsB8R2uAWzIAh2HLokjAekCL0UgQUy4oA9CY=; b=kG+dryLDhDG7JVD4Dttq3EAI9AibzSTL2xeEprXglVmiaKV+dyvhCstoVOZcE+CH7n bjkiGKQ8EHRopMgDOlTORbUbp3ByC3dAXZlZJiisxE0Y/ExH7GEtiF44HcLKi5r3B8kE DEYB/KGk+SaoMFl30AksIh7lkdppHYkIFe8J/Gwo+QIbyLgTHjte7sWW5O/nCeoIo24T 9drnzA8A0HNWuQ9DONSkwidmhBrKb5oq1g/xeqaJwsMFlBwJotEcqW6TvseLq+EGKysQ DaQSKPeLZifTd1hZHekbFWEFzoOVRSc1XQBwy8yJgXqeYTzg06/62hq4wsc4T50uUR6e L+Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L56K0bKB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x18si141669ejo.233.2021.03.10.10.53.25; Wed, 10 Mar 2021 10:53:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=L56K0bKB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233065AbhCJSuV (ORCPT + 99 others); Wed, 10 Mar 2021 13:50:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57287 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233403AbhCJSuP (ORCPT ); Wed, 10 Mar 2021 13:50:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615402214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ujgHC2APsB8R2uAWzIAh2HLokjAekCL0UgQUy4oA9CY=; b=L56K0bKBiFyC97iMybfm5jPe1GT8hMnQD9L7G1BAw0OIZGHvvKqPz921Zg4U327lgMZacQ Dos2U2FcRcw/6ITSQ/56TU7S1AHcs53FndJBDfoHtS3pJCpJd977zCwHxQGiZE53h1qn46 vjXKVpG/B7zGlFU4nyKuhRQ+65INLOs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-552-huHmzua5PeKRAYpDhp0a9Q-1; Wed, 10 Mar 2021 13:50:10 -0500 X-MC-Unique: huHmzua5PeKRAYpDhp0a9Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6891618D6A40; Wed, 10 Mar 2021 18:50:08 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.38]) by smtp.corp.redhat.com (Postfix) with SMTP id A5BA177BF0; Wed, 10 Mar 2021 18:50:03 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 10 Mar 2021 19:50:08 +0100 (CET) Date: Wed, 10 Mar 2021 19:50:02 +0100 From: Oleg Nesterov To: Piotr Figiel Cc: Andrew Morton , mathieu.desnoyers@efficios.com, peterz@infradead.org, paulmck@kernel.org, boqun.feng@gmail.com, ldv@altlinux.org, fweimer@redhat.com, Alexey Dobriyan , Andrei Vagin , linux-kernel@vger.kernel.org, posk@google.com, kyurtsever@google.com, ckennelly@google.com, pjt@google.com, emmir@google.com, linux-man@vger.kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCH v2] ptrace: add PTRACE_GET_RSEQ_CONFIGURATION request Message-ID: <20210310185001.GD8973@redhat.com> References: <20210226135156.1081606-1-figiel@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210226135156.1081606-1-figiel@google.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I don't think I can review this patch, I don't understand the problem space well enough. But just in case, I see nothing wrong in this simple patch. Feel free to add Acked-by: Oleg Nesterov On 02/26, Piotr Figiel wrote: > > For userspace checkpoint and restore (C/R) a way of getting process state > containing RSEQ configuration is needed. > > There are two ways this information is going to be used: > - to re-enable RSEQ for threads which had it enabled before C/R > - to detect if a thread was in a critical section during C/R > > Since C/R preserves TLS memory and addresses RSEQ ABI will be restored > using the address registered before C/R. > > Detection whether the thread is in a critical section during C/R is needed > to enforce behavior of RSEQ abort during C/R. Attaching with ptrace() > before registers are dumped itself doesn't cause RSEQ abort. > Restoring the instruction pointer within the critical section is > problematic because rseq_cs may get cleared before the control is passed > to the migrated application code leading to RSEQ invariants not being > preserved. C/R code will use RSEQ ABI address to find the abort handler > to which the instruction pointer needs to be set. > > To achieve above goals expose the RSEQ ABI address and the signature value > with the new ptrace request PTRACE_GET_RSEQ_CONFIGURATION. > > This new ptrace request can also be used by debuggers so they are aware > of stops within restartable sequences in progress. > > Signed-off-by: Piotr Figiel > Reviewed-by: Michal Miroslaw > > --- > v2: > Applied review comments: > - changed return value from the ptrace request to the size of the > configuration structure > - expanded configuration structure with the flags field and > the rseq abi structure size > > v1: > https://lore.kernel.org/lkml/20210222100443.4155938-1-figiel@google.com/ > > --- > include/uapi/linux/ptrace.h | 10 ++++++++++ > kernel/ptrace.c | 25 +++++++++++++++++++++++++ > 2 files changed, 35 insertions(+) > > diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h > index 83ee45fa634b..3747bf816f9a 100644 > --- a/include/uapi/linux/ptrace.h > +++ b/include/uapi/linux/ptrace.h > @@ -102,6 +102,16 @@ struct ptrace_syscall_info { > }; > }; > > +#define PTRACE_GET_RSEQ_CONFIGURATION 0x420f > + > +struct ptrace_rseq_configuration { > + __u64 rseq_abi_pointer; > + __u32 rseq_abi_size; > + __u32 signature; > + __u32 flags; > + __u32 pad; > +}; > + > /* > * These values are stored in task->ptrace_message > * by tracehook_report_syscall_* to describe the current syscall-stop. > diff --git a/kernel/ptrace.c b/kernel/ptrace.c > index 61db50f7ca86..76f09456ec4b 100644 > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > > #include /* for syscall_get_* */ > > @@ -779,6 +780,24 @@ static int ptrace_peek_siginfo(struct task_struct *child, > return ret; > } > > +#ifdef CONFIG_RSEQ > +static long ptrace_get_rseq_configuration(struct task_struct *task, > + unsigned long size, void __user *data) > +{ > + struct ptrace_rseq_configuration conf = { > + .rseq_abi_pointer = (u64)(uintptr_t)task->rseq, > + .rseq_abi_size = sizeof(*task->rseq), > + .signature = task->rseq_sig, > + .flags = 0, > + }; > + > + size = min_t(unsigned long, size, sizeof(conf)); > + if (copy_to_user(data, &conf, size)) > + return -EFAULT; > + return sizeof(conf); > +} > +#endif > + > #ifdef PTRACE_SINGLESTEP > #define is_singlestep(request) ((request) == PTRACE_SINGLESTEP) > #else > @@ -1222,6 +1241,12 @@ int ptrace_request(struct task_struct *child, long request, > ret = seccomp_get_metadata(child, addr, datavp); > break; > > +#ifdef CONFIG_RSEQ > + case PTRACE_GET_RSEQ_CONFIGURATION: > + ret = ptrace_get_rseq_configuration(child, addr, datavp); > + break; > +#endif > + > default: > break; > } > -- > 2.30.1.766.gb4fecdf3b7-goog >