Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp969668pxb; Fri, 22 Apr 2022 15:36:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyo3tCNFqxx0vdYj5qtR33sUXHDKXG7bApyzg/VYTjrO1bjPDUOe73gZjB7Bo3qja9vH7VC X-Received: by 2002:a17:90b:4b0e:b0:1d2:c23b:553f with SMTP id lx14-20020a17090b4b0e00b001d2c23b553fmr7849726pjb.160.1650666983231; Fri, 22 Apr 2022 15:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650666983; cv=none; d=google.com; s=arc-20160816; b=NjS4zjY9BiPp2NFlF/XW1dHiNSLhmswPQrQXay1ZCPyn9E9BCu2uaQK5l4BR3CXqmV Z4a2s0Kjc6wU+eIW7aHV5jLGzkUlqdm5hSvaD5ne5W40R581xJ7SN5+TRO2uwwXkinT9 OFJnRG1TXspSbdYiZ8F5/arDQI4pesslL+R64tGk6UgAt3NM/8PtpyqTafhTZOoY9/03 0OJ4NEVH4ziz82Tt3gnL2HXCs7CSl11fm1oIyxPov0ltjR0T6RtVO+w2W7xZ4GV6b2az nDKj5ZpkyOgX423wfwBJ8EjqTzjhqCOugh1ySpCbo/CJP6Nl5ytKZqFuJUQEklvkyMwe f40A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=eupx91ipHUfoNRi4brayBvoybEh9b09e5p2b6SLiofg=; b=c8PZ3K4eRoICaOa35ltg1CPhpDz+YVtFUT5s04t2zLmv55wjfYjZ29rtaZSfs9ZXJ4 oKY8MIbWjaizv+fABuFZPKROEJnDOrLtAT5tRcL9J02E/2GK5dkGz+GoI1Y5/DkSXqv7 9fsQyPvLgD4UrqS23CSzMPQ8gNrekr+0chf6+LlcqTq4Cs5ONTE4WRP+Nsv7wXRtsuFa mySxOxqMCovHlh+M8abMiGk9IEelRy3hP9JOF4pEExNR75y8+ya/hJaooXTO4+9yCuD9 mhSC4JLJK0mdqCQKs+CEm71Mn0gU5JvoUUSrvfQoc+zf0rXMI2b+1qeaTP+qvNz4+wjK 7isQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cI4CmBOR; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c4-20020a170902724400b0015895212d3asi9268237pll.290.2022.04.22.15.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:36:23 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=cI4CmBOR; dkim=neutral (no key) header.i=@linutronix.de; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0140126887C; Fri, 22 Apr 2022 13:24:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351449AbiDSNG4 (ORCPT + 99 others); Tue, 19 Apr 2022 09:06:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241707AbiDSNGx (ORCPT ); Tue, 19 Apr 2022 09:06:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68A32377F7 for ; Tue, 19 Apr 2022 06:04:09 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1650373447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eupx91ipHUfoNRi4brayBvoybEh9b09e5p2b6SLiofg=; b=cI4CmBORYShGFfnHSNBz9VGYvmJmfBwTLETF0Z+PuDFf2wTU9JTPwNPBirPKGGFshg//ha hEm01DvI077mODBNvpXZmwmvGGMWqAmdNMd/4/ZU7LkaGNK+MH4oMc1HsdrR2A2y9ToDN9 dfvQYeRyQlJUbZY4c55MJJWGX3LXUKGf9VYOGlL0TsqvacsFbZhO1FhClqBpnu2SGWmCvc 7lSq2jkCKicVMT+fSn4X3fajQycGrcV+2XuHYsXNYlQ5/Qqc33b1GqObujveM64Ce16zdH ATr4Od3B9zAyALcKk5CEKccPtc3Ysh6p38t04yUemeqV4CmuHDWqLziruWEyPQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1650373447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eupx91ipHUfoNRi4brayBvoybEh9b09e5p2b6SLiofg=; b=rZwxEQnkdn25xC4vmQ1vWWlUtUGc2zX9kYvqyN9BrZ3mVG/9Iy+L5nK7KWr1dF4b/jpdj5 d8tqyF7f42zAWYBA== To: Dave Hansen , LKML Cc: x86@kernel.org, Andrew Cooper , "Edgecombe, Rick P" Subject: Re: [patch 2/3] x86/fpu/xsave: Prepare for optimized compaction In-Reply-To: References: <20220404103741.809025935@linutronix.de> <20220404104820.656881574@linutronix.de> Date: Tue, 19 Apr 2022 14:39:36 +0200 Message-ID: <87k0bl9rhz.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 14 2022 at 08:46, Dave Hansen wrote: > On 4/4/22 05:11, Thomas Gleixner wrote: > Any interest in doing something like the attached to make > copy_uabi_to_xstate() easier to read? Yeah. I've picked it up. >> +static void xsave_adjust_xcomp(struct fpstate *fpstate, u64 xuser) >> +{ >> + struct xregs_state *xsave = &fpstate->regs.xsave; >> + u64 xtmp, xall, xbv, xcur = xsave->header.xfeatures; >> + int i; >> + >> + /* Nothing to do if optimized compaction is not in use */ >> + if (!xsave_use_xgetbv1()) >> + return; > > The comment makes me wonder if we need a more descriptive name for > xsave_use_xgetbv1(), like: > > if (!xsave_do_optimized_compaction()) > return; Makes sense. >> + /* >> + * No more optimizations. Set the user features and move the >> + * supervisor state(s). If the new user feature is past >> + * the supervisor state, then the loop is moving nothing. >> + */ >> + xtmp = xbv & XFEATURE_MASK_SUPERVISOR_ALL; >> + xall = xbv | xuser; > > > I'd probably at least comment why the loop is backwards: > > /* > * Features are only be moved up in the buffer. Start with > * high features to avoid overwriting them with a lower ones. > */ > > I know this is a very typical way to implement non-destructive moves, > but my stupid brain seems to default to assuming that for loops only go > forward. :) >> + for (i = fls64(xtmp) - 1; i >= FIRST_EXTENDED_XFEATURE; >> + i = fls64(xtmp) - 1) { >> + unsigned int to, from; > > Is it worth a check here like: > > /* Do not move features in their init state: */ > if (!(xcur & BIT_ULL(i))) { > xtmp &= ~BIT_ULL(i); > continue; > } That would also require to clear the bit in xall, but we can't do that in the loop as that affects offsets. Let me think about that. Thanks, tglx