From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 03A69C433E2 for ; Thu, 3 Sep 2020 16:09:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C776420716 for ; Thu, 3 Sep 2020 16:09:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C776420716 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 70CB86B005D; Thu, 3 Sep 2020 12:09:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BDB26B0068; Thu, 3 Sep 2020 12:09:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B4BE6B005D; Thu, 3 Sep 2020 12:09:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0065.hostedemail.com [216.40.44.65]) by kanga.kvack.org (Postfix) with ESMTP id 4199F6B005D for ; Thu, 3 Sep 2020 12:09:10 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EDAF91F08 for ; Thu, 3 Sep 2020 16:09:09 +0000 (UTC) X-FDA: 77222234418.29.gun62_0b0dd83270aa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 8AE09180868E5 for ; Thu, 3 Sep 2020 16:09:09 +0000 (UTC) X-HE-Tag: gun62_0b0dd83270aa X-Filterd-Recvd-Size: 4975 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Sep 2020 16:09:06 +0000 (UTC) IronPort-SDR: lM0QYFvX9j3bNUnBffK+MEJy1zLpJpWnb8FffPNbXfuI05f0cbTwtbN6+JTFXg+WQTKLPK68y5 sD6QvoMCYMMQ== X-IronPort-AV: E=McAfee;i="6000,8403,9733"; a="145305079" X-IronPort-AV: E=Sophos;i="5.76,387,1592895600"; d="scan'208";a="145305079" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 09:09:03 -0700 IronPort-SDR: +C92qNo6vPQliFbZvRVoLeCI4c58RtTTyJZLqSfKqMdZx/NGqhVaiuZEkTHCzNP6ihEpbCixYB VQvGXEsgZUUQ== X-IronPort-AV: E=Sophos;i="5.76,387,1592895600"; d="scan'208";a="503116307" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.209.173.133]) ([10.209.173.133]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 09:09:01 -0700 Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET To: Dave Hansen , Andy Lutomirski Cc: Jann Horn , the arch/x86 maintainers , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang References: <46e42e5e-0bca-5f3f-efc9-5ab15827cc0b@intel.com> <40BC093A-F430-4DCC-8DC0-2BA90A6FC3FA@amacapital.net> From: "Yu, Yu-cheng" Message-ID: <88261152-2de1-fe8d-7ab0-acb108e97e04@intel.com> Date: Thu, 3 Sep 2020 09:09:01 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Queue-Id: 8AE09180868E5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 Content-Transfer-Encoding: quoted-printable 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: On 9/3/2020 7:26 AM, Dave Hansen wrote: > On 9/2/20 9:35 PM, Andy Lutomirski wrote: >>>>>>> + fpu__prepare_read(fpu); >>>>>>> + cetregs =3D get_xsave_addr(&fpu->state.xsave, XFEATURE_CE= T_USER); >>>>>>> + if (!cetregs) >>>>>>> + return -EFAULT; >>>>>> Can this branch ever be hit without a kernel bug? If yes, I think >>>>>> -EFAULT is probably a weird error code to choose here. If no, this >>>>>> should probably use WARN_ON(). Same thing in cetregs_set(). >>>>> When a thread is not CET-enabled, its CET state does not exist. I = looked at EFAULT, and it means "Bad address". Maybe this can be ENODEV, = which means "No such device"? >> Having read the code, I=E2=80=99m unconvinced. It looks like a get_xsa= ve_addr() failure means =E2=80=9Cstate not saved; task sees INIT state=E2= =80=9D. So *maybe* it=E2=80=99s reasonable -ENODEV this, but I=E2=80=99m= not really convinced. I tend to think we should return the actual INIT s= tate and that we should permit writes and handle them correctly. >=20 > PTRACE is asking for access to the values in the *registers*, not for > the value in the kernel XSAVE buffer. We just happen to only have the > kernel XSAVE buffer around. When get_xsave_addr() returns NULL, there are three possibilities: - XSAVE is not enabled or not supported; - The kernel does not support the requested feature; - The requested feature is in INIT state. If the debugger is going to write an MSR, only in the third case would=20 this make a slight sense. For example, if the system has CET enabled,=20 but the task does not have CET enabled, and GDB is writing to a CET MSR.=20 But still, this is strange to me. >=20 > If we want to really support PTRACE we have to allow the registers to b= e > get/set, regardless of what state they are in, INIT state or not. So, > yeah I agree with Andy. >=20 GDB does not have a WRMSR mechanism. If GDB is going to write an MSR,=20 it will call arch_prctl or an assembly routine in memory. Yu-cheng