Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5595276pxb; Tue, 16 Feb 2021 02:36:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTcJESYMTzf6ps2Ui66lAKa50pXuZ9MM+mZt1sj8YQQBOefvO4q6W1eEeEdBegi/5hG5QQ X-Received: by 2002:a05:6402:204b:: with SMTP id bc11mr9879569edb.241.1613471794886; Tue, 16 Feb 2021 02:36:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613471794; cv=none; d=google.com; s=arc-20160816; b=t/Tstj+ZUhTNMnmmJosMp8mjOPQ6xhqiwzUCKFTsqRU/MLAe2XAQijmjCPdUkK66t9 WZjZ/YxlVwB7QycrpO+qUzBYBAXuekiCcAJqxaysWnLE1Oba9lF44eTnOQ+G3Q4voJZA 6v+0vvZ9rglrvOuzUIJiEikakIxAiVfCXOtBtavN6rPgA5no8aHOz+PdNTINm269RrQr +/jip0yd11zk0hLYQPUP+upa1rG8Jke8ep1kqdJfUuCH42UlOFw1/se/sERuX+bFMHHv Zsq4zCp6mx73QexvWXI/s8e8dz04eVL+mT+AD1rrOe8w8B9sjDuBIaEJfDLjKESV87/r wJuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zDOLcrLf12OYTMH5bu47751maxGqogIZVRk/BjJrAhA=; b=XIBUVxy6FqMnJq1Bx7Y3IwsrR6hYVhdbdNRZg5YqxtL1lH5tIr/6rVuCZVpTYgh5A0 VP5kWZncF3nSqzZ6bVP6eW+xD2kWmrEimsETs8WTPmyQQaYybuEhbioEZY4+21HUuvd3 L7AEp6MhvIXjNYZkFk/ClyKCPpqiCxIdcXmhPY4gckrbBuz/wA1tMyo3iL/WYo7B5dxo 4BVE9UFJ/P8eux/uhaN7RM+FVMjNtM5e09wn8VH2Tz83EjsfB+sHhri5edUyVT8+rLeJ dE9Dk/351BaknkBQ+Ce+Idc2P0DB/JxNDxB0N8JytGFx7naE3BlS9KOFBk6jXa6ncaTu bjYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DXioZDTw; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si8408189edw.269.2021.02.16.02.36.05; Tue, 16 Feb 2021 02:36:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DXioZDTw; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbhBPKfy (ORCPT + 99 others); Tue, 16 Feb 2021 05:35:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:60064 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbhBPKfw (ORCPT ); Tue, 16 Feb 2021 05:35:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 98F0264E00; Tue, 16 Feb 2021 10:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613471711; bh=2W9VGlDi6NiRZ8mjUgWkcUO+fkrD9CT0ZH5lsbWfrEU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=DXioZDTwzPDIlGSizhs8rWfUJYgS2Tuc+cqT64jvlfj5io8N1/9EA8f0M/fEqAYec NVlXcOi79+2xaXle0ruTahXbL6TVK6wMOB1ryXzPQQB0GmNBkoJQgEyLyAxcvO2Snb 81y8KWvP6O5S380MdroFj3g4PclQDrp0RLn2cyB0IUrdy4vIfpWOmS5OYOZQQS76El oBOrWlsnDNKSdBO0HoiUB9OUhaZlThamowPKwu4ZWpi91GzgOjGFheChSl2bWsX/Am XfglT+NOibIQbjCRGvb/qplT4XOfo1fQ++xh2lRQddEOxREimtlmhA7kW1QZFcivdQ kLQFmr+coLqbg== Received: by mail-ot1-f50.google.com with SMTP id v3so3417165ota.2; Tue, 16 Feb 2021 02:35:11 -0800 (PST) X-Gm-Message-State: AOAM530BEETGY2LLO3JItTsaYBcYSppWj6y1LtNSMJjStQjFYURe9cAB dJldha0xWck5eJOrp1I98ZlcHJ64xhOYX6Ipiu8= X-Received: by 2002:a05:6830:1285:: with SMTP id z5mr14564809otp.90.1613471710852; Tue, 16 Feb 2021 02:35:10 -0800 (PST) MIME-Version: 1.0 References: <20201218170106.23280-1-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Tue, 16 Feb 2021 11:35:00 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 0/5] running kernel mode SIMD with softirqs disabled To: Peter Zijlstra Cc: Linux Crypto Mailing List , Linux ARM , Linux Kernel Mailing List , Dave Martin , Mark Brown , Herbert Xu , Eric Biggers , Will Deacon , Catalin Marinas , Thomas Gleixner , Sebastian Andrzej Siewior , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, 16 Feb 2021 at 11:10, Peter Zijlstra wrote: > > On Fri, Dec 18, 2020 at 06:01:01PM +0100, Ard Biesheuvel wrote: > > [ TL;DR for the non-ARM folks on CC: disabling softirq processing when using > > SIMD in kernel mode could reduce complexity and improve performance, but we > > need to decide whether we can do this, and how much softirq processing > > latency we can tolerate. If we can find a satisfactory solution for this, > > we might do the same for x86 and 32-bit ARM as well. ] > > > - could we do the same on x86, now that kernel_fpu_begin/end is no longer > > expensive? > > Can't we simply save/restore the relevant register set? > > So something like (note amluto was wanting to add a regset argument): > > > kernel_fpu_begin(MMX) > > kernel_fpu_begin(SSE) > kernel_fpu_end(); > > ... > kernel_fpu_end() > > Would have to save the MMX regs on first SIRQ invocation of > kernel_fpu_begin(), and then have softirq context termination > above, restore it. > > I mean, we already do much the same for the first kernel_fpu_begin(), > that has to save the user registers, which will be restore when we go > back to userspace. > > So why not do exactly the same for softirq context? That is what we originally had on arm64, with per-CPU buffers of the appropriate size. This became a bit messy when SVE support was added, because the register file is so large (32 registers of up to 2048 bits each), and since the kernel does not use SVE itself, we want the inner per-CPU buffer to only cover 128 bits per register. This means we cannot allow the region above to interrupt the outer preserve (which is implemented entirely in software), since resuming the outer preserve after a sirq would preserve content that was corrupted by the inner preserve/restore. This could be addressed by disabling interrupts across the outer preserve, but this caused a problem somewhere else (Dave might remember the details better than I do). So we ended up making SIMD in task context mutually exclusive with SIMD in softirq context, also because that is what 32-bit ARM and x86 were already doing as well. But I understand that these concerns may not apply to x86 at all, so perhaps the answer there is indeed to have a alternate buffer. And actually, Andy L. suggested the same when I asked him about it on IRC.