Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4954750imm; Sun, 26 Aug 2018 07:27:14 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda5zWoGX6BYGc99LMGnI54Chmfw005v0BOFCZ0P5HmeHykFr6cW7UGN870W0jqjtIsCrzcB X-Received: by 2002:a62:d544:: with SMTP id d65-v6mr10252836pfg.107.1535293634330; Sun, 26 Aug 2018 07:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535293634; cv=none; d=google.com; s=arc-20160816; b=dfnSfuzraai+/d9OjqE2Q0s/Z6MGXV7kjJFxqIk2yL/Ws06nbms/BOKz1wZxPW7DJ1 7gqexj2twxZ/mnnk383dmDF3P+hxd96tfnfbHJG7VgxNJV3N2Z11xw0Kwg50owyh3RWp 0Xg3KC93ovqcMr1IkeJ8TiVJd1Q+/WUCNfnH3Lc7zEeEW+qFg9Kn+HkCE0m7bBk5cUzw i/OdzrIaBHcA8u7PHbLrVN89a3wrHaxMdgsDE7PEWbOh/vfezUgnnxJTEGNViY/acOmG gehrMeEn12wQM3hB6pCMPkxWorS7D8PuYO66QhinxbAlJOhRWC5i2Y8jbTS6eg8fFie9 EoSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=Br+F6ackvix8jTckjfbh8xxY5EG6ueq5gvpzi79uiBE=; b=bBV1s4By7dqxei9Z651zvlvZ+xU7OKSMIAV/FiLa+bNVPmjvxObVSWp6taXtrANNz8 svvLlS3JfvwMPxMcV3F+ANPI/3oePw+n4m9bhy/soB2PeBsiZzpPq4xb2og6e4YOr9Sl nny1KWdfpRnGhnKwo0xl0iJHSvICe6vxmT34/WODxqXQsSM0Epamu2ttnJLzEV81G5A3 4kBsf5f8nWAC2q6kyXTw1gEwCXfpN1j2gEeOaO5rafNWvxxu3NQYwf4ObSBkT8ZnDi3v F9tXaSI6GgU0XDgQLUln5yYh+xU7dt9hdqoLr2M3P6EPbj5CaBp0pegx+U+OQXgN+hOv DolA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=R8DBeRn0; 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 gn19si8032359plb.186.2018.08.26.07.26.58; Sun, 26 Aug 2018 07:27: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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=R8DBeRn0; 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 S1726930AbeHZSHr (ORCPT + 99 others); Sun, 26 Aug 2018 14:07:47 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35719 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726500AbeHZSHq (ORCPT ); Sun, 26 Aug 2018 14:07:46 -0400 Received: by mail-pg1-f196.google.com with SMTP id z4-v6so6264116pgv.2 for ; Sun, 26 Aug 2018 07:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Br+F6ackvix8jTckjfbh8xxY5EG6ueq5gvpzi79uiBE=; b=R8DBeRn0JOCvB6N0OJOmhsG6CGVVREgWGCG4knNlv4/OV/sL/4j/E88iWInl1VRk4r sq/YnqPlBX3URlXwtzC4U7f1oLw4d/xtRTNJufHB7mqTnJpLHSJ3yLQ+ocM2HAfu3QI3 fkG6W54WnWR4pq6IQbhZsBLoS5Ec8tEF+H+DWdZxlQ3AZPj1oZN7HXazjfOYoqGpa7TC rwMDlcg0C8ah95YNx4ZxBo9H1Ha/NBsYb1oA4j+WZOCmIMaIXuON+A2Ai7j8440Ton8b dIcQEhoW7nvN+04Gn3cJ02rRiS6vjWvS/Pc3U7DW+wroHvLZ66aYcCLecUYxaHGv5MY8 ev3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Br+F6ackvix8jTckjfbh8xxY5EG6ueq5gvpzi79uiBE=; b=W6IXQqO5MyCJXHD2QjU3HQmhz59G7L/ohXEwqai1f53+YG783QEBw3yAMxqYyid7Vi A2H6IBW7MJS59D6TtYxqcmBiIQt9yFJAb2vgy3mSySifMPWn6HjjrwnsEcm6vG2gSvah rcep4BymULaM8XLfLkWT71q54vw0K9OWHQASCCHP/YyZqhRHfD6TqN/tTK2S2//KH5XQ VOdvduDCiz7LsxdK3UvQ9jzqiFZ/hdXhe7cUGDo6f+3B1vW9J1a8Bek0cnd1FT/ASc1J z3kcUdNR3BdYKqJxLq0/fdWSxQVmSBVsvQ/lKYLkVDFUIYXqLK2GN+OsCHwGclV9WNQ6 le1Q== X-Gm-Message-State: APzg51DCrpMuf9Jur1DUeLMVa6UgHSYJuDXQHAWQzcmyfcKWebDG9/YN BJZkOXSUA3XPbtdDDLsx58AKEA== X-Received: by 2002:a63:1250:: with SMTP id 16-v6mr186184pgs.299.1535293503400; Sun, 26 Aug 2018 07:25:03 -0700 (PDT) Received: from ?IPv6:2601:646:c200:7429:a803:ac38:1531:22f8? ([2601:646:c200:7429:a803:ac38:1531:22f8]) by smtp.gmail.com with ESMTPSA id t19-v6sm18390696pfk.182.2018.08.26.07.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Aug 2018 07:25:02 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v2 01/17] asm: simd context helper API From: Andy Lutomirski X-Mailer: iPhone Mail (15G77) In-Reply-To: Date: Sun, 26 Aug 2018 07:25:01 -0700 Cc: Thomas Gleixner , LKML , Netdev , David Miller , Andrew Lutomirski , Greg Kroah-Hartman , Samuel Neves , linux-arch@vger.kernel.org, Rik van Riel Content-Transfer-Encoding: quoted-printable Message-Id: <01BF319B-D6F3-432F-AE1A-1B8B4E3A36A4@amacapital.net> References: <20180824213849.23647-1-Jason@zx2c4.com> <20180824213849.23647-2-Jason@zx2c4.com> To: "Jason A. Donenfeld" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Aug 26, 2018, at 7:18 AM, Jason A. Donenfeld wrote: >=20 > On Sun, Aug 26, 2018 at 8:06 AM Thomas Gleixner wrote= : >>> Do you mean to say you intend to make kernel_fpu_end() and >>> kernel_neon_end() only actually do something upon context switch, but >>> not when it's actually called? So that multiple calls to >>> kernel_fpu_begin() and kernel_neon_begin() can be made without >>> penalty? >>=20 >> On context switch and exit to user. That allows to keep those code pathes= >> fully preemptible. Still twisting my brain around the details. >=20 > Just to make sure we're on the same page, the goal is so that this code: >=20 > kernel_fpu_begin(); > kernel_fpu_end(); > kernel_fpu_begin(); > kernel_fpu_end(); > kernel_fpu_begin(); > kernel_fpu_end(); > kernel_fpu_begin(); > kernel_fpu_end(); > kernel_fpu_begin(); > kernel_fpu_end(); > kernel_fpu_begin(); > kernel_fpu_end(); > ... >=20 > has the same performance as this code: >=20 > kernel_fpu_begin(); > kernel_fpu_end(); >=20 > (Unless of course the process is preempted or the like.) >=20 > Currently the present situation makes the performance of the above > wildly different, since kernel_fpu_end() does something immediately. >=20 > What about something like this: > - Add a tristate flag connected to task_struct (or in the global fpu > struct in the case that this happens in irq and there isn't a valid > current). > - On kernel_fpu_begin(), if the flag is 0, do the usual expensive > XSAVE stuff, and set the flag to 1. > - On kernel_fpu_begin(), if the flag is non-0, just set the flag to 1 > and return. > - On kernel_fpu_end(), if the flag is non-0, set the flag to 2. > (Otherwise WARN() or BUG() or something.) > - On context switch / preemption / etc away from the task, if the flag > is non-0, XRSTOR and such. It=E2=80=99s not that simple. First, these states need names, at least for t= hinking about. 0 is =E2=80=9Cuser state in regs=E2=80=9D. 1 is =E2=80=9Ckern= el state active=E2=80=9D. 2 is =E2=80=9Cnothing active=E2=80=9D. The actual encoding will be something like TIF_XSTATE_UNLOADED: user state i= s not in regs. TIF_KERNEL_XSTATE: kernel is using FPU. And this fundamental= ly doubles the size of struct fpu. Tglx, that doubling-the-size-of-fpu makes me question the idea of letting th= e kernel use the fpu while preemptible. > - On context switch / preemption / etc back to the task, if the flag > is 1, XSAVE and such. If the flag is 2, set it to 0. >=20 > Jason