Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1739528imu; Wed, 28 Nov 2018 14:24:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/XWrnwcGf8rPXBqkPN8fPl9CLwWvkpFv8P3E5deocsHv/yhZSQTRqyV+0aD3WAi17YYyEWZ X-Received: by 2002:a17:902:7c0c:: with SMTP id x12mr39651805pll.265.1543443842764; Wed, 28 Nov 2018 14:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543443842; cv=none; d=google.com; s=arc-20160816; b=wMuS4QMNlwOWZ0OGMvrnWYsYnLH07m++8Fklj/msnuFWrw7rn/zyQkUbBE42eoqK+J C15oCZNNQ6S0HXJt2HfLVc46fiX+KAoJtKAyReKz7xDX7OKszQLeEfu2I3/ETZiwp5us BBgAeV7wBYXH8in1N4DSAApZaRjHCnOwKKdyd1En3LapznWdrUpFfkmrUP0mlsmyMgxG l96H2MVCJGgV17SOVXxWJh9/QU1s0REqg1ISnMt4KVxqaRCNQN0KbRaDiLi9Ef9uKNiK IIEJIRw1cU8iIO91t9c6XhleY2GmgxAdswHxKsiPAp1CHHmHeNxCR5RMd6LCuJ4oialB 1VFw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=r8nJjF8/vK4Q5Nd+OGszyQ6E4wnY8abg458YvMIoiDM=; b=0w8OFlqirbouQG/C+P4nOqQ7t6OJE+Cs3edBJ7R8FoGBeuf4O6oByRsrEOD3bUlThl fMQPA/RX8gMzMPbHaeCP8E2ox3I5eOx1CYiEZSv8QCrs7hH5BXRq/RlqtF2yonsndRqA f9fnfkYZ7Qtgj93Tb/PgPkXK8tOoKoupVMrZBGwMXm2uoJ9Hh1tHmyfi/Z5j7z4VuytS XcljkES6psMhCmCjhSj/ObOvDBvnpqY54jA79eZrKrBAAVr0XlM9lamNsA5YY3YcKN4b onLqPNGxMvL8Pp3Kcf7Ki6XGJO/J/Dcqefzn/82HwWhYZtS60yqYvfMgeE+BuKeD5V+f 6kSQ== 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 i13si8428458pgg.100.2018.11.28.14.23.47; Wed, 28 Nov 2018 14:24:02 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727097AbeK2JY2 (ORCPT + 99 others); Thu, 29 Nov 2018 04:24:28 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:33162 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726870AbeK2JY1 (ORCPT ); Thu, 29 Nov 2018 04:24:27 -0500 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gS8Ck-0001GX-O2; Wed, 28 Nov 2018 23:21:11 +0100 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Andy Lutomirski , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel , Dave Hansen , Sebastian Andrzej Siewior Subject: [PATCH 17/29] x86/fpu: Make __raw_xsave_addr() use feature number instead of mask Date: Wed, 28 Nov 2018 23:20:23 +0100 Message-Id: <20181128222035.2996-18-bigeasy@linutronix.de> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181128222035.2996-1-bigeasy@linutronix.de> References: <20181128222035.2996-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Most users of __raw_xsave_addr() use a feature number, shift it to a mask and then __raw_xsave_addr() shifts it back to the feature number. Make __raw_xsave_addr() use the feature number as an argument. Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/kernel/fpu/xstate.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index a85f4139f663d..0e759a032c1c7 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -805,20 +805,18 @@ void fpu__resume_cpu(void) } /* - * Given an xstate feature mask, calculate where in the xsave + * Given an xstate feature nr, calculate where in the xsave * buffer the state is. Callers should ensure that the buffer * is valid. */ -void *__raw_xsave_addr(struct xregs_state *xsave, int xstate_feature_mask) +static void *__raw_xsave_addr(struct xregs_state *xsave, int xfeature_nr) { - int feature_nr = fls64(xstate_feature_mask) - 1; - - if (!xfeature_enabled(feature_nr)) { + if (!xfeature_enabled(xfeature_nr)) { WARN_ON_FPU(1); return NULL; } - return (void *)xsave + xstate_comp_offsets[feature_nr]; + return (void *)xsave + xstate_comp_offsets[xfeature_nr]; } /* * Given the xsave area and a state inside, this function returns the @@ -840,6 +838,7 @@ void *__raw_xsave_addr(struct xregs_state *xsave, int xstate_feature_mask) */ void *get_xsave_addr(struct xregs_state *xsave, int xstate_feature) { + int xfeature_nr; /* * Do we even *have* xsave state? */ @@ -867,7 +866,8 @@ void *get_xsave_addr(struct xregs_state *xsave, int xstate_feature) if (!(xsave->header.xfeatures & xstate_feature)) return NULL; - return __raw_xsave_addr(xsave, xstate_feature); + xfeature_nr = fls64(xstate_feature) - 1; + return __raw_xsave_addr(xsave, xfeature_nr); } EXPORT_SYMBOL_GPL(get_xsave_addr); @@ -1014,7 +1014,7 @@ int copy_xstate_to_kernel(void *kbuf, struct xregs_state *xsave, unsigned int of * Copy only in-use xstates: */ if ((header.xfeatures >> i) & 1) { - void *src = __raw_xsave_addr(xsave, 1 << i); + void *src = __raw_xsave_addr(xsave, i); offset = xstate_offsets[i]; size = xstate_sizes[i]; @@ -1100,7 +1100,7 @@ int copy_xstate_to_user(void __user *ubuf, struct xregs_state *xsave, unsigned i * Copy only in-use xstates: */ if ((header.xfeatures >> i) & 1) { - void *src = __raw_xsave_addr(xsave, 1 << i); + void *src = __raw_xsave_addr(xsave, i); offset = xstate_offsets[i]; size = xstate_sizes[i]; @@ -1157,7 +1157,7 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf) u64 mask = ((u64)1 << i); if (hdr.xfeatures & mask) { - void *dst = __raw_xsave_addr(xsave, 1 << i); + void *dst = __raw_xsave_addr(xsave, i); offset = xstate_offsets[i]; size = xstate_sizes[i]; @@ -1211,7 +1211,7 @@ int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf) u64 mask = ((u64)1 << i); if (hdr.xfeatures & mask) { - void *dst = __raw_xsave_addr(xsave, 1 << i); + void *dst = __raw_xsave_addr(xsave, i); offset = xstate_offsets[i]; size = xstate_sizes[i]; -- 2.20.0.rc1