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=-4.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 BCD4FC433E1 for ; Fri, 24 Jul 2020 17:29:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 829C820674 for ; Fri, 24 Jul 2020 17:29:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=amacapital-net.20150623.gappssmtp.com header.i=@amacapital-net.20150623.gappssmtp.com header.b="oCF2bACf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 829C820674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amacapital.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 18D486B002B; Fri, 24 Jul 2020 13:29:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 165016B002C; Fri, 24 Jul 2020 13:29:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0518D6B002D; Fri, 24 Jul 2020 13:29:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id E4C676B002B for ; Fri, 24 Jul 2020 13:29:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6C2EE8248068 for ; Fri, 24 Jul 2020 17:29:29 +0000 (UTC) X-FDA: 77073656058.08.shoes11_1c0bf3e26f49 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 4400B1801302B for ; Fri, 24 Jul 2020 17:29:29 +0000 (UTC) X-HE-Tag: shoes11_1c0bf3e26f49 X-Filterd-Recvd-Size: 6610 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 17:29:28 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id o22so5681852pjw.2 for ; Fri, 24 Jul 2020 10:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=xVJb6QB7yJwnn1Z6Ovzuc7SiH2/mFZI/eEetibZkjak=; b=oCF2bACf0J3wi10Mkevj6a1lx9ZJ2XYqftXol/Y5C3BUVETOi1ThoRhsL2OxKFCyb4 LGJ3ZE9QuRoT+dYLR9CdhNjE9P+KA1F0J34lD0z4Rjmsdl1uULCFsHQh/kjIrw/3yYIN MIxEx6ObahD1W2wfYbyu5J04MgrODyT6hzuLM3mpaqgWNY1btI1HYMmRRqfrG327H9oM z5+CURUIEaZafgf40maNhBKcXiwP+sIOTIqvFURURI9WNSOzDt9L7YckftzfASDKb67X c6S0yxsINqy7Fs9MCqKwbe5ZznH0YewS4KMFQ8V9Fo2+D3qH4LKoiOb9hjdKp/ooZMns 71UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=xVJb6QB7yJwnn1Z6Ovzuc7SiH2/mFZI/eEetibZkjak=; b=q9RWGNIadWONVQ/IUxVTFp9SO/s1T+0pbL+4IHoaYbOZR9rm/B/1raBqV6xKxv/Uku NTf0md5VjzOSQL4y6NZOArTpr04ILrUumg1jtNN9V87+b+0+yLO+UR3nodnvG2WtVFP4 v21xIYtjYIhWKvVqsqhHYosUae8pIpFrbnN841Zzn0Bey2vJonh6enU/AncNrNZ2sYrY +VbpWlWLOdyEwaPJxurQqcT7A/9BM74XXj9dF2XbQOpKIQLpBHLA/6nTw2GXoT5XW7Uz tkADKo4s2RmSUWi6djd2kzGSE+2nQzAjalp/Y4QWT9rd+ZzcnWFpgzhnj0VHPmQxUwdb Wfsw== X-Gm-Message-State: AOAM531ReDHTyhf33LusesLyd5xZamLnbnN4lo79JL/0d02Xwe67whzS D3zDY0kJ3gfuWY6Er2s5UL2srw== X-Google-Smtp-Source: ABdhPJxgGZkOO3kQzBrpxCwHwlk1F6DYD0lzx0NwksvJwkCVThBWugwQYsACXzFP/Kw/IrlXRyq2VQ== X-Received: by 2002:a17:90a:1b2c:: with SMTP id q41mr6495292pjq.195.1595611767681; Fri, 24 Jul 2020 10:29:27 -0700 (PDT) Received: from ?IPv6:2601:646:c200:1ef2:cc1b:c95e:6185:cfc7? ([2601:646:c200:1ef2:cc1b:c95e:6185:cfc7]) by smtp.gmail.com with ESMTPSA id x66sm6882326pgb.12.2020.07.24.10.29.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jul 2020 10:29:27 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH RFC V2 17/17] x86/entry: Preserve PKRS MSR across exceptions Date: Fri, 24 Jul 2020 10:29:23 -0700 Message-Id: References: <20200724172344.GO844235@iweiny-DESK2.sc.intel.com> Cc: Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Dave Hansen , x86@kernel.org, Dan Williams , Vishal Verma , Andrew Morton , Fenghua Yu , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org In-Reply-To: <20200724172344.GO844235@iweiny-DESK2.sc.intel.com> To: Ira Weiny X-Mailer: iPhone Mail (17F80) X-Rspamd-Queue-Id: 4400B1801302B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 Jul 24, 2020, at 10:23 AM, Ira Weiny wrote: >=20 > =EF=BB=BFOn Thu, Jul 23, 2020 at 10:15:17PM +0200, Thomas Gleixner wrote: >> Thomas Gleixner writes: >>=20 >>> Ira Weiny writes: >>>> On Fri, Jul 17, 2020 at 12:06:10PM +0200, Peter Zijlstra wrote: >>>>>> On Fri, Jul 17, 2020 at 12:20:56AM -0700, ira.weiny@intel.com wrote: >>>>> I've been really digging into this today and I'm very concerned that I= 'm >>>>> completely missing something WRT idtentry_enter() and idtentry_exit().= >>>>>=20 >>>>> I've instrumented idt_{save,restore}_pkrs(), and __dev_access_{en,dis}= able() >>>>> with trace_printk()'s. >>>>>=20 >>>>> With this debug code, I have found an instance where it seems like >>>>> idtentry_enter() is called without a corresponding idtentry_exit(). T= his has >>>>> left the thread ref counter at 0 which results in very bad things happ= ening >>>>> when __dev_access_disable() is called and the ref count goes negative.= >>>>>=20 >>>>> Effectively this seems to be happening: >>>>>=20 >>>>> ... >>>>> // ref =3D=3D 0 >>>>> dev_access_enable() // ref +=3D 1 =3D=3D> disable protection >>>>> // exception (which one I don't know) >>>>> idtentry_enter() >>>>> // ref =3D 0 >>>>> _handler() // or whatever code... >>>>> // *_exit() not called [at least there is no trace_printk()= output]... >>>>> // Regardless of trace output, the ref is left at 0 >>>>> dev_access_disable() // ref -=3D 1 =3D=3D> -1 =3D=3D> does not enab= le protection >>>>> (Bad stuff is bound to happen now...) >>>=20 >>> Well, if any exception which calls idtentry_enter() would return without= >>> going through idtentry_exit() then lots of bad stuff would happen even >>> without your patches. >>>=20 >>>> Also is there any chance that the process could be getting scheduled an= d that >>>> is causing an issue? >>>=20 >>> Only from #PF, but after the fault has been resolved and the tasks is >>> scheduled in again then the task returns through idtentry_exit() to the >>> place where it took the fault. That's not guaranteed to be on the same >>> CPU. If schedule is not aware of the fact that the exception turned off >>> stuff then you surely get into trouble. So you really want to store it >>> in the task itself then the context switch code can actually see the >>> state and act accordingly. >>=20 >> Actually thats nasty as well as you need a stack of PKRS values to >> handle nested exceptions. But it might be still the most reasonable >> thing to do. 7 PKRS values plus an index should be really sufficient, >> that's 32bytes total, not that bad. >=20 > I've thought about this a bit more and unless I'm wrong I think the > idtentry_state provides for that because each nested exception has it's ow= n > idtentry_state doesn't it? Only the ones that use idtentry_enter() instead of, say, nmi_enter(). >=20 > Ira