Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp92689ybb; Tue, 7 Apr 2020 17:41:23 -0700 (PDT) X-Google-Smtp-Source: APiQypIjD/HnQmg0poTgrOTCIWfG6HTTjAqlYl5UyuPhCdvOlNLnQrwFYYpptXDEa6+Ogl5cL1YJ X-Received: by 2002:a05:6830:1495:: with SMTP id s21mr4037364otq.35.1586306483403; Tue, 07 Apr 2020 17:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586306483; cv=none; d=google.com; s=arc-20160816; b=wnWc9IJsTnvDqG5i1i4OJG2oGfKSUwY2bWcz8ZjACaEY6vpJHKtdEl3pMFjubkdo3c 9+3p3tx7f8CUJMIC/VndFO6PQy0vlBh9HGhXGtT0DHpH19z/WA0NMoYyrS9GdQqnV4pt mk4DhyLfWrIDfEQoEIpD9LN9PKh9Enfrx8WuG2lr82xKz5hQ0I3P3pscuzKwUlMigKxF m5UmhLpeDdFnQ9jBLWWP/+c7ByQSdILzvFGjoNhp7Gs6jdmObdUrOTTfeKTgSWjaqLN2 OoBDJxjMHO+MFMlzraejyAGsl2wBVK3sf+crIKBHqQaaISzkQ911AYyikJcAoNHQ7PS6 fjAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=WREvrkmaAxP/lGkmOD/HeF2WSM7vp8PO9gSzIhvvLgQ=; b=DoJ3XQtOWqTmsTq23wIecafDqnwrNzoUXg9iBxwOBcbFY/gbDwMgGktPfieHczi6Kk xO3qWMpppHbv5C0a1FYuCY8XPO/TOMdgqu3muIcod5g3NQ1Xx5j3HApbWgLgJT8gTyvv UIbVtWx8A6bg+gt/D2o8D82/1o+ra7/zOY4dlZQfy9Xvq3vcsv0NYldj5Csia5xCoS4F IKZ5e1PCFG14W4MqrHrCukCUYPys6PhKGq+zQkb7dzbIWSNMYNjK/WceLQe8AGxYIM1T 6bPgGoqR1BIhxkST7qyzS7QK3k3O0/XDMXJnwGvqHRlYmzeyJ2Pvtiyi1T2zGvtReKB1 18/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=mail header.b=3TcYGnYj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9si1158029otp.52.2020.04.07.17.41.09; Tue, 07 Apr 2020 17:41:23 -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=@zx2c4.com header.s=mail header.b=3TcYGnYj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726443AbgDHAkU (ORCPT + 99 others); Tue, 7 Apr 2020 20:40:20 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:34299 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726421AbgDHAkU (ORCPT ); Tue, 7 Apr 2020 20:40:20 -0400 Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id 1cff259c for ; Wed, 8 Apr 2020 00:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=mime-version :references:in-reply-to:from:date:message-id:subject:to:cc :content-type; s=mail; bh=pVZbz2BQiRw2Mi3KrA8/Yoa+8c8=; b=3TcYGn Yj01O9WWE/XKUXtg4fDPrqV69tp2+JqTx4aclm3f7Q46GJY//9rcpEoQYPOrMPEs drxICokhgcw03fi/N93H+fnRqF60Pw9tZOfw91moZCYnS+h/DVrLMrVYwqUY5h2J KcHrfHEgb2+So579x6808LkgeC1SO47sPFYOmEQeWKulCmDJF3ituSwsLFs7Rz6y fKlTepo+50ybdmQfTqYvrVAjKYMP76uR5SX4hMVI3TccA9MfTgBM/AZpF76+XGVf 25VyWRylR6eC/Sh8eYIOhskkPxE1Sc087qrux8s5yk+he4mJcdPtDhzhwlQq8OoZ M2uVtWOhuOzeeweg== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 56d6b9a8 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for ; Wed, 8 Apr 2020 00:31:19 +0000 (UTC) Received: by mail-il1-f177.google.com with SMTP id o11so878509ilq.7 for ; Tue, 07 Apr 2020 17:40:18 -0700 (PDT) X-Gm-Message-State: AGi0Pua4iegLbb5jdVUCADN60JOMdllHg5bTGAgkPMSO8pR6otay2wJ8 19OEez9xReLnDjRtN+XMypPz1lAUEKIgaKsu/QU= X-Received: by 2002:a92:798f:: with SMTP id u137mr5578644ilc.231.1586306418050; Tue, 07 Apr 2020 17:40:18 -0700 (PDT) MIME-Version: 1.0 References: <20200328000422.98978-1-Jason@zx2c4.com> <158538232569.25292.15795048542441478192@build.alporthouse.com> In-Reply-To: <158538232569.25292.15795048542441478192@build.alporthouse.com> From: "Jason A. Donenfeld" Date: Tue, 7 Apr 2020 18:40:07 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] drm/i915: check to see if the FPU is available before using it To: Chris Wilson Cc: dri-devel , intel-gfx@lists.freedesktop.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 28, 2020 at 1:59 AM Chris Wilson wrote: > > Quoting Jason A. Donenfeld (2020-03-28 00:04:22) > > It's not safe to just grab the FPU willy nilly without first checking to > > see if it's available. This patch adds the usual call to may_use_simd() > > and falls back to boring memcpy if it's not available. > > These instructions do not use the fpu, nor are these registers aliased > over the fpu stack. This description and the may_use_simd() do not > look like they express the right granularity as to which simd state are > included Most of the time when discussing vector instructions in the kernel with x86, "FPU" is used to denote the whole shebang, because of similar XSAVE semantics and requirements with actual floating point instructions and SIMD instructions. So when I say "grab the FPU", I'm really referring to the act of messing with any registers that aren't saved and restored by default during context switch and need the explicit marking for XSAVE to come in -- the kernel_fpu_begin/end calls that you already have. With regards to the granularity here, you are in fact touching xmm registers. That means you need kernel_fpu_begin/end, which you correctly have. However, it also means that before using those, you should check to see if that's okay by using the may_use_simd() instruction. Now you may claim that at the moment may_use_simd()-->irq_fpu_usable()-->(!in_interrupt() || interrupted_user_mode() || interrupted_kernel_fpu_idle()) always holds true, and you're a keen follower of the (recently changed) kernel fpu x86 semantics in case those conditions change, and that your driver is so strictly written that you know exactly the context this fancy memcpy will run in, always, and you'll never deviate from it, and therefore it's okay to depart from the rules and omit the check and safe fallback code. But c'mon - i915 is complex, and mixed context bugs abound, and the rules for using those registers might in fact change without you noticing. So why not apply this to have a safe fallback for when the numerous assumptions no longer hold? (If you're extra worried I suppose you could make it a `if (WARN_ON(!may_use_simd()))` instead or something, but that seems like a bit much.) > Look at caller, return the error and let them decide if they can avoid > the read from WC, which quite often they can. And no, this is not done > from interrupt context, we would be crucified if we did. Ahh, now, reading this comment here I realize maybe I've misunderstood you. Do you mean to say that checking for may_use_simd() is a thing that you'd like to do after all, but you don't like it falling back to slow memcpy. Instead, you'd like for the code to return an error value, and then caller can just optionally skip the memcpy under some complicated driver circumstances? Jason