Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2529496imm; Thu, 7 Jun 2018 12:11:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKPvOBBiLU5Py7SGIA4n4sXVYVO626T3QDfC/5m+q6j+pjpkP3hjuaC+Zov3Cbb5EQyHeI9 X-Received: by 2002:a17:902:9b92:: with SMTP id y18-v6mr3247909plp.57.1528398683380; Thu, 07 Jun 2018 12:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528398683; cv=none; d=google.com; s=arc-20160816; b=maszerJxIRw4d8tjEali2EyNISXTiegRfTiiiLwVoK9BQ4u5do70R6xfknJiNagVt+ Cs41i+W+7gu8w0wHejrudkz/nO1DypUcvxoxsSgMWcCm1JeXVADkZahs/jvdWBSfXJQg rup5IBEUwWORsieHnLVIg5oaDe8Sa169Z3SHfqhKJWaR7vnE9nfsIONuZkFwfWBNLw1D b3PSmf2NJvoeniCrVOEXvk7Rmn3KWYIjoT50C47eftrk6d64fhuDIt4ZO4gkixvl2mT6 MaBAibTUbBFfQ7fGcSsojxCmRnC4+aveSZjeAtcX3zqUPDkrmka5FX9Sc7Yt9Sa4oJrn wIIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=14lqIxu6tcrCdagy6uH9m4DflnRkLAEokF03mK09sls=; b=vqXD3fjCgoTnHMMTj0Frs8zKOZ0fbOjRUc78KEr4QQB/B26LrutwrrZFPG+F4xWdju kTqzVIwJJC3oXsIMCdaJ2csOLldpbhtEeDYpLoPSJoFfP6PPZrGUhLj34JZEEk5d0mm7 wUbNWG7MIuBCyz2a4sBMdII46pdXJ17ohOWE4tnAf1ZGYRmqeLRY7gytaGEyieQ16sZy lGaKVlcK4g9j2I34P+wuhAH8HXMJmswUdYhr+FlKn55fkneeIDPVygz85uHGzBeb6lNp XOGph2idu8MIJ9bTNYNUX/vXBI5ead/TuXyXVU8viHt+k6Uix6xD04A81j5WI+tzAZOO x27g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=fNRxn2Ic; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h127-v6si58402187pfb.111.2018.06.07.12.11.08; Thu, 07 Jun 2018 12:11:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=fNRxn2Ic; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936352AbeFGScx (ORCPT + 99 others); Thu, 7 Jun 2018 14:32:53 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:55422 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936334AbeFGSct (ORCPT ); Thu, 7 Jun 2018 14:32:49 -0400 Received: by mail-wm0-f65.google.com with SMTP id v16-v6so19777628wmh.5 for ; Thu, 07 Jun 2018 11:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=14lqIxu6tcrCdagy6uH9m4DflnRkLAEokF03mK09sls=; b=fNRxn2Ic2VllwqgMynJUFcfiuVJ3b9mavZehlCDy9aXEyJnF5U7dFteQgR2qpivPrr Kpozr8B5IfyI5chNUQZRZ4L+yN98dVD2mS876XMNzcjfd/UY8xj/oKeB7LWd7idwiT83 8t7LJQQhack1O7TyEiohmBZqtOOHW30jCKIaGr7Gk8fZ63TvEbibfwAm3vgOr2mM0MpT b7xV+c9PAb9Il+/lvR5O7IGthgR1vzE9ig5dOm5ky/w1FD19HnYnGNh3gfL7BujYNO68 73KSvdpRw2MCFPgDiCpjMES62EnFHeYNj1AxbEdFP0hUmkAne4rmVdRBxLREKhZ8LcZ7 M06A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=14lqIxu6tcrCdagy6uH9m4DflnRkLAEokF03mK09sls=; b=ZZEVmvKoShngudHeoN+u73aIxD0c/LoD4xuV2gFCkREMiLoifZpHIy0qoK3AJfVMrq 05GoDcKFhKf4MHvDXSAxItfX68AaB7RBfsL6uh3QzmJ387P2ToTDHp6Z6WDpcoRjxD1j n5Mov4Lt+LLxqHdHygKYWiDZ7oxz5iauABZWCkYoKOLhmtcYBl7HzYu7N9GHzNANjUrX gE9Z5mC+v4YL5EZlgzBBFt/XdML/hLKKbLn0DPzWml4PX6HtkfrZjvezj03OqhpGi3HF ldcvlUjUn+vUjsDvTuIhyoiLVfO2QdAXU0HVYGvogPUTocZHSy5iyVp+8FG5PW1VqE1o bNVw== X-Gm-Message-State: APt69E162JKgoUXZSPhEGRml9sOHrSnnqAZzkGfLHLRfHwhziM80qz3+ RYiSHtjPHih4U1aYncb2vvaH8K1VrbE1vCGH+2Jvlg== X-Received: by 2002:a1c:f902:: with SMTP id x2-v6mr2230370wmh.116.1528396368522; Thu, 07 Jun 2018 11:32:48 -0700 (PDT) MIME-Version: 1.0 References: <20180607143855.3681-1-yu-cheng.yu@intel.com> <20180607143855.3681-8-yu-cheng.yu@intel.com> In-Reply-To: <20180607143855.3681-8-yu-cheng.yu@intel.com> From: Andy Lutomirski Date: Thu, 7 Jun 2018 11:32:36 -0700 Message-ID: Subject: Re: [PATCH 7/7] x86/cet: Add PTRACE interface for CET To: Yu-cheng Yu Cc: LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H. J. Lu" , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 7, 2018 at 7:42 AM Yu-cheng Yu wrote: > > Add PTRACE interface for CET MSRs. > > Signed-off-by: Yu-cheng Yu > --- > arch/x86/include/asm/fpu/regset.h | 7 ++++--- > arch/x86/kernel/fpu/regset.c | 41 +++++++++++++++++++++++++++++++++++++++ > arch/x86/kernel/ptrace.c | 16 +++++++++++++++ > include/uapi/linux/elf.h | 1 + > 4 files changed, 62 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/include/asm/fpu/regset.h b/arch/x86/include/asm/fpu/regset.h > index d5bdffb9d27f..edad0d889084 100644 > --- a/arch/x86/include/asm/fpu/regset.h > +++ b/arch/x86/include/asm/fpu/regset.h > @@ -7,11 +7,12 @@ > > #include > > -extern user_regset_active_fn regset_fpregs_active, regset_xregset_fpregs_active; > +extern user_regset_active_fn regset_fpregs_active, regset_xregset_fpregs_active, > + cetregs_active; > extern user_regset_get_fn fpregs_get, xfpregs_get, fpregs_soft_get, > - xstateregs_get; > + xstateregs_get, cetregs_get; > extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set, > - xstateregs_set; > + xstateregs_set, cetregs_set; > > /* > * xstateregs_active == regset_fpregs_active. Please refer to the comment > diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset.c > index bc02f5144b95..7008eb084d36 100644 > --- a/arch/x86/kernel/fpu/regset.c > +++ b/arch/x86/kernel/fpu/regset.c > @@ -160,6 +160,47 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset, > return ret; > } > > +int cetregs_active(struct task_struct *target, const struct user_regset *regset) > +{ > +#ifdef CONFIG_X86_INTEL_CET > + if (target->thread.cet.shstk_enabled || target->thread.cet.ibt_enabled) > + return regset->n; > +#endif > + return 0; > +} > + > +int cetregs_get(struct task_struct *target, const struct user_regset *regset, > + unsigned int pos, unsigned int count, > + void *kbuf, void __user *ubuf) > +{ > + struct fpu *fpu = &target->thread.fpu; > + struct cet_user_state *cetregs; > + > + if (!boot_cpu_has(X86_FEATURE_SHSTK)) > + return -ENODEV; This whole series has a boot_cpu_has, static_cpu_has, and cpu_feature_enabled all over. Please settle on just one, preferably static_cpu_has. > + > + cetregs = get_xsave_addr(&fpu->state.xsave, XFEATURE_MASK_SHSTK_USER); > + > + fpu__prepare_read(fpu); > + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, cetregs, 0, -1); > +} > + > +int cetregs_set(struct task_struct *target, const struct user_regset *regset, > + unsigned int pos, unsigned int count, > + const void *kbuf, const void __user *ubuf) > +{ > + struct fpu *fpu = &target->thread.fpu; > + struct cet_user_state *cetregs; > + > + if (!boot_cpu_has(X86_FEATURE_SHSTK)) > + return -ENODEV; > + > + cetregs = get_xsave_addr(&fpu->state.xsave, XFEATURE_MASK_SHSTK_USER); > + > + fpu__prepare_write(fpu); > + return user_regset_copyin(&pos, &count, &kbuf, &ubuf, cetregs, 0, -1); Is this called for core dumping on current? If so, please make sure it's correct. (I think it is for get but maybe not for set.)