Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2209317imd; Fri, 2 Nov 2018 07:43:14 -0700 (PDT) X-Google-Smtp-Source: AJdET5cqyUIooBUYpvu6/9lQ6h/cRO8nKMmS3uJQyGbVHpTj4FpIg6xrYV715EY1bxBkUTj+1JgO X-Received: by 2002:a17:902:7004:: with SMTP id y4-v6mr11938190plk.35.1541169794035; Fri, 02 Nov 2018 07:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541169794; cv=none; d=google.com; s=arc-20160816; b=KJ0BrV04SCM3lIgtMF8oHseJtnJR1LCg7RN/J+tl7hrpZmTD7yEDgyxxaRRLT83Xqp 8Ccak/lI7tH9kQVNjGfIpgzMuOV6LUuD4VVoPPhN5w7RkRPjbEfmC1v2PrGMBVZTIWpL kvtcTqdcfuhV+s++rQbRy3/bh2Z6A06c5CX2/ISUAYRzsgDly5pxzziKnJ3/QYxRP6Ly P40KJfFmzWJhFK02wpvsXFU7THw0Q+lVumm57tJrT7ZV2sHNFv7pTIuYtK+E81pSZjUQ lLyoP1V3QPoxm7JqscRrJLKdRAl+CGM3Aotv9puQGJxD1SQAQEiC9SIqmQlvRZcv0nep RQSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eMc14rUlSEO1LKGSy+LS3akeS+UGCKaHihc6H5Mmmvk=; b=i1Fs/ScXy2ys8Lx8M5j8VdEgMNBVp9cAHRDub0u5cu12g7ivqDq42fmHvO2KmlFSov rKYA7glob5Z6PzM8uDOg9c1/YJcDiVmyS+nvt3dvujDdhvLien4aK7DMZudBia8YX0Eq Z5vLjxJlh4SEdT6PVJK7661qxK7uCpmsuVFvaga8mY4PH4w66Ofegjc0flMJxqsTGFaS bPVjrFQjqJ30f93Reb5BSALu2ZdQC8MuDQnnG+5/s/C/jL0FVUZQgk4gfPnGW70pp3iL 34XP5/JEnuHM/h/eJyJk31SevrGm1+7CsvZv3befWD1zq5bizDr6fJknQH4hKD63pOCg 26Dw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66-v6si19199796pfv.38.2018.11.02.07.42.59; Fri, 02 Nov 2018 07:43:14 -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; 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 S1727874AbeKBXtz (ORCPT + 99 others); Fri, 2 Nov 2018 19:49:55 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:59216 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726557AbeKBXty (ORCPT ); Fri, 2 Nov 2018 19:49:54 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1gIaea-0007UL-7s; Fri, 02 Nov 2018 15:42:28 +0100 Date: Fri, 2 Nov 2018 15:42:28 +0100 From: Sebastian Andrzej Siewior To: Dave Hansen Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel Subject: Re: [PATCH 08/11] x86/fpu: Always store the registers in copy_fpstate_to_sigframe() Message-ID: <20181102144227.nugzdwmis6oecis7@linutronix.de> References: <20181004140547.13014-1-bigeasy@linutronix.de> <20181004140547.13014-9-bigeasy@linutronix.de> <53f013ca-d6ff-2387-f9b0-d6c6df66d082@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <53f013ca-d6ff-2387-f9b0-d6c6df66d082@linux.intel.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-10-12 11:15:51 [-0700], Dave Hansen wrote: > > @@ -172,27 +155,20 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size) > > sizeof(struct user_i387_ia32_struct), NULL, > > (struct _fpstate_32 __user *) buf) ? -1 : 1; > > > > - if (fpu->initialized || using_compacted_format()) { > > - /* Save the live register state to the user directly. */ > > - if (copy_fpregs_to_sigframe(buf_fx)) > > - return -1; > > - /* Update the thread's fxstate to save the fsave header. */ > > - if (ia32_fxstate) > > - copy_fxregs_to_kernel(fpu); > > + /* Update the thread's fxstate to save the fsave header. */ > > + if (ia32_fxstate) { > > + copy_fxregs_to_kernel(fpu); > > } else { > > - /* > > - * It is a *bug* if kernel uses compacted-format for xsave > > - * area and we copy it out directly to a signal frame. It > > - * should have been handled above by saving the registers > > - * directly. > > - */ > > - if (boot_cpu_has(X86_FEATURE_XSAVES)) { > > - WARN_ONCE(1, "x86/fpu: saving compacted-format xsave area to a signal frame!\n"); > > - return -1; > > - } > > + copy_fpregs_to_fpstate(fpu); > > + fpregs_deactivate(fpu); > > + } > > Could you add a high-level comment for this if{}else{} block that says > something like: > > /* Save the registers to the fpstate. */ > > I also think it's worthwhile to explain the asymmetry between the > ia32_fxstate case and the other branch. Why don't we > fpregs_deactivate() in the ia32_fxstate path, for instance? Since the ->initialized is gone, the whole hunk here looks differently and probably easier to understand. > > + if (using_compacted_format()) { > > + copy_xstate_to_user(buf_fx, xsave, 0, size); > > + } else { > > fpstate_sanitize_xstate(fpu); > > - if (__copy_to_user(buf_fx, xsave, fpu_user_xstate_size)) > > + size = fpu_user_xstate_size; > > + if (__copy_to_user(buf_fx, xsave, size)) > > return -1; > > } dropped this. > This seems unnecessary. Why are you updating 'size' like this? Sebastian