Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3640142ybl; Fri, 20 Dec 2019 12:53:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyZipTg4VIhs4K4FQZ45hZ5lHnVX7YOSLG0UkwWYfHNQVd5dSBNwRFlUKUB3lSirlUuJ/7j X-Received: by 2002:a9d:66c1:: with SMTP id t1mr15294444otm.73.1576875215844; Fri, 20 Dec 2019 12:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576875215; cv=none; d=google.com; s=arc-20160816; b=vm9w+dFgB6TaiZ848noLQJN4FWibeusEef+SIidCsNpJAQaYPFHkDKlEl3Rthv82o4 lcJp0bxMY9qkEteOKF6odv4qYHeoPktsks+WNheY8shLv19w8Xx7qsSceQAhlYqo1kE4 LR8gr+47hDEaNka+rTgCRr7NkKhLLJXjlpSr+W3g7pZZnd/tCBxn38Qtxqbx1Vkj3V8V 4DkXYRlF2cpfh3vxOqBBIPovKpaQriQt+RBVLP5Tv2j1yRFsmRAY+OKA8Cb9Zr+UCX7q k4J7UPyXsqk3l2/rG0t/XaQQIYJXHiGdx3kvjmX23LEkpiX9Gbspjqqvc8VDng5sOiPS pHuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=lqC1YndfXgHLR1u+qr77GvbGysqvTwfLCb/D7hYaQfU=; b=PMT4wXa3sJw3yWsQo7l+IS1PSRI5b1rIbBvnT1ctx1ME5bTpFt5Y0+fQ5biFNjViXh 3vyEeySsSMAQxmdnDXra+60E9kUgamwNv/jiq56RtyfBdYjz5W293KJ/WpnZ3vHY+Is/ /Bkr3mVy0HCr4zqbNdjGff6k0Cpwem8qFD0CjQ4/IIYgyR9OWocPvtDHCCziqZp3u8t2 AKt28XzUjAGApI4kYx6tHtEiUY5Hgr7cJV09TmBw+D4nmOeoL6n/jhACzEEy8CpvIPnf HxwkVUfYKpgiSM9h9iB3YsRAeleBxwd6y8/IyndkJBRtMe/h/fA3IsLoG5+w9omq20+l LC1g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si2271728otf.66.2019.12.20.12.53.22; Fri, 20 Dec 2019 12:53:35 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727517AbfLTUvW (ORCPT + 99 others); Fri, 20 Dec 2019 15:51:22 -0500 Received: from mga01.intel.com ([192.55.52.88]:12377 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727422AbfLTUvV (ORCPT ); Fri, 20 Dec 2019 15:51:21 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Dec 2019 12:51:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,337,1571727600"; d="scan'208";a="210926531" Received: from yyu32-desk.sc.intel.com ([143.183.136.51]) by orsmga008.jf.intel.com with ESMTP; 20 Dec 2019 12:51:20 -0800 Message-ID: Subject: Re: [PATCH v2 3/3] x86/fpu/xstate: Invalidate fpregs when __fpu_restore_sig() fails From: Yu-cheng Yu To: Sebastian Andrzej Siewior Cc: linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Dave Hansen , Tony Luck , Andy Lutomirski , Borislav Petkov , Rik van Riel , "Ravi V. Shankar" , Fenghua Yu , Peter Zijlstra Date: Fri, 20 Dec 2019 12:32:36 -0800 In-Reply-To: <20191220201621.riyrptl5vwdukztc@linutronix.de> References: <20191212210855.19260-1-yu-cheng.yu@intel.com> <20191212210855.19260-4-yu-cheng.yu@intel.com> <20191218155449.sk4gjabtynh67jqb@linutronix.de> <587463c4e5fa82dff8748e5f753890ac390e993e.camel@intel.com> <20191219142217.axgpqlb7zzluoxnf@linutronix.de> <19a94f88f1bc66bb81dbf5dd72083d03ca5090e9.camel@intel.com> <20191219171635.phdsfkvsyazwaq7s@linutronix.de> <1607597639a6c6255127fef07704ee9193e33166.camel@intel.com> <20191220201621.riyrptl5vwdukztc@linutronix.de> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-12-20 at 21:16 +0100, Sebastian Andrzej Siewior wrote: > [...] > Now that I looked at it: > All kernel loads don't fail. If they fail we end up in the handler and > restore to init-state. So no need to reset `fpu_fpregs_owner_ctx' in this > case. The variable is actually set to task's FPU state so resetting is > not required. Agree. > fpu__save() invokes copy_kernel_to_fpregs() (on older boxes) and by > resetting `fpu_fpregs_owner_ctx' we would load it twice (in fpu__save() > and on return to userland). That is true. > So far I can tell, the only problematic case is the signal code because > here the state restore *may* fail and we *may* do it in two steps. The > error happens only if both `may' are true. > > > > So if this patch works for you and you don't find anything else where it > > > falls apart then I will audit tomorrow all callers which got the > > > "invalidator" added and check for that angle. > > > > Yes, that works for me. Also, most of these call sites are under fpregs_lock(), > > and we could use __cpu_invalidate_fpregs_state(). > > I was also thinking maybe add warnings when any new code re-introduces the issue, > > but not sure where to add that. Do you think that is needed? > > I was thinking about it. So the `read-FPU-state' function must be > invoked within the fpregs_lock() section. This could be easily > enforced. At fpregs_unlock() time `fpu_fpregs_owner_ctx' must be NULL or > pointing to task's FPU. > My brain is fried for today so I'm sure if this is a sane approach. But > it might be a start. I will also think about it. Thanks! Yu-cheng