Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp1067738lqp; Thu, 23 May 2024 08:07:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfHE2TVJESSHVTcDGm2IsF087Z/9u1kaLQa/eenL00pkyKoEsBk24jpOoineDAMFmg9jja0hcAVYmwH5GxauvFAL0nvnemwVxtiJGyzQ== X-Google-Smtp-Source: AGHT+IGEP0w9wL1EfeERZs9wTl/Xlo3xBzLUecLWkn7m04LqQoBChuSI6caEY8T7n6eAPe+6NlBK X-Received: by 2002:a05:6a21:6d9f:b0:1b0:1a80:4136 with SMTP id adf61e73a8af0-1b1f8845187mr5752755637.4.1716476874140; Thu, 23 May 2024 08:07:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716476874; cv=pass; d=google.com; s=arc-20160816; b=obF7NK1xaINh34KDQD+V/fnQuW2xkohvXIUhC9+RqXVVihC2sNbVMzf4xXhc3YoOhJ fr1iIVr+0w8FxVWlOEOU7tgl6l6w3N6xKNlCmrkqA8a/Vus4FwRgR5wQrnPmXDS4JqfS +sxELTshtdbEjxYZfL5MGYXK56L3EKsPbIb7A8k1bm3YIyrQWzfmU9f9JyY8Mw71M/Qx CeN+ExsnFcit8/nw60NWL2XwCQZW0Se5lYGN+rvjI4sNzAMiWo7erhSRSXDnO3pKuo/h 2faNKbncjK233A9Wt4cmpgV5Sj982QnEkDEzVxsOpzCYs7BRUTYG1MtQFCzRCIN/hZXR QUjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=s2lYMgKhqmOoc2ZsDL1yCZHZwFkT2+ILqBEJ2uaDiAI=; fh=+CmvJ6Y1X/AnKSkpHUEvRSBWkVreS9i6MlLznoOb0Y4=; b=ogmoUFXWT2u5A+JClXvJZKzTQTPH38yrtmJhYASerV/iqQz6fqaXsH2uucyACueluR iIku3ZJRgJvIo2xpLC7E8rf/jiD8yXlf7wygRSnERvvuc/HZ1nRHUOz8240rmLusaODG CwcA665EPaPAJUq6griCWGzso1DFDplFJhPTbarHLGpvfh6GIzDy5P3CirdA4r1dHFZn JAbB/ReVhIm1LU1imB8TWgqwRxP2ANJBYpSgPqGi9K8qcMnSfXtIj3baZ+Go4+Zjnxt+ Gu4LICntlxNXX9Y4sVfgKp8MfQunjw0jJxVEM5varnNOFbT/Tl8HnLjo9R+/NZhsfjZ3 JwNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@citrix.com header.s=google header.b=LiAF9et4; arc=pass (i=1 spf=pass spfdomain=cloud.com dkim=pass dkdomain=citrix.com dmarc=pass fromdomain=citrix.com); spf=pass (google.com: domain of linux-kernel+bounces-187682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187682-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=citrix.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-662f2cbbd50si10503603a12.7.2024.05.23.08.07.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 08:07:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@citrix.com header.s=google header.b=LiAF9et4; arc=pass (i=1 spf=pass spfdomain=cloud.com dkim=pass dkdomain=citrix.com dmarc=pass fromdomain=citrix.com); spf=pass (google.com: domain of linux-kernel+bounces-187682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187682-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=citrix.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6F7F5287385 for ; Thu, 23 May 2024 15:00:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E72FD14A85; Thu, 23 May 2024 15:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="LiAF9et4" Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4762F125A9 for ; Thu, 23 May 2024 15:00:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716476405; cv=none; b=b1XiubKpGCPtMdRl4DV/L5l/qqgR9u24bPsHPUwoJkB1IQU1WFDR4bp5OZOIn4GzC+NA3udv0e35DX1/pmOCtO5y0r23Bls2HnBVJeoIqADD+rS9oaS1LXn+bdpcYw1DQzlEXoBqneWNT5Djlt4GjQ5RN7aCO250vxjeZRgoCsI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716476405; c=relaxed/simple; bh=s2lYMgKhqmOoc2ZsDL1yCZHZwFkT2+ILqBEJ2uaDiAI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JNB3Poj/W+DM2L/7OpFRPetaHft3S0QDfLtTP1JtU6994/Y+jxaij31AOMuDAwp0NuXQgO0+s/OGDFuipBzcHZuQiohxj8qw6/wvkULxFMLBn3OHKXJ/HWTeue5JchtSYyxCYLwjD0q+l+cFPiKnh1FWW5OdfQvW2ucBAtv4hoA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com; spf=pass smtp.mailfrom=cloud.com; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b=LiAF9et4; arc=none smtp.client-ip=209.85.160.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloud.com Received: by mail-qt1-f178.google.com with SMTP id d75a77b69052e-43df7f42ac9so12043851cf.2 for ; Thu, 23 May 2024 08:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716476403; x=1717081203; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=s2lYMgKhqmOoc2ZsDL1yCZHZwFkT2+ILqBEJ2uaDiAI=; b=LiAF9et4e6YqmOY1K4Nm8yJO97KIGfkUcf4SiqVOOEFSFS+SiaH49u/zW/Wm3Bps42 5Ry0I2FCbrs9YwlnKnuIaZY3JMWZQ4ltGv7K2U3DwSPMHeCxVurwmfU9ZJ8rSTP5Mw+P FLxs9qRWuMCG+9PHCNi38Y5/m8T6jA7mYooTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476403; x=1717081203; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=s2lYMgKhqmOoc2ZsDL1yCZHZwFkT2+ILqBEJ2uaDiAI=; b=psrEn4FKQbMKwSTXgQZ87r9BlBp7YEYE5ckmn1NM7mpd0V1odae0uHmF1/CPO3sMsa qifXS2aye2S21uTO75sDrfx7CKO6xWGhCz1mCLYbMvw3CBpvDxVQOuzcy2pkVjLCa1CI mrLObsnX3QYM8drMdHbQSFHY3hsc/4Mn0l+Ef/PEufY91FxOpZ1fRdy0TI4OXkTBs9tX cnW+sPFouQ3gGvKEh5dyiisBtkz/L9LQ4/2OThOki48kX0SEwrBxNdvG/XiXfzi3HuPf Iw/lk9s13USwhDq9uqk/r4WjHUVEIWxufYgF+I+v2frVdFc73WT/HcjmzwWqKiGAFsiO Rbtw== X-Gm-Message-State: AOJu0YyNXqm+9/Nj4eH5OG7pDtufFEums0pX7y9nVgS5OBRxizklHG9W OFsqx3NzbRgckRHsYtEz9l2c4f0fx/l1WVMuyjI43W5NTRuJVrP87iGOYiVJatg= X-Received: by 2002:a05:622a:54d:b0:43a:f58b:2e71 with SMTP id d75a77b69052e-43f9e0849fbmr48737101cf.10.1716476403146; Thu, 23 May 2024 08:00:03 -0700 (PDT) Received: from [10.125.231.30] ([217.156.233.157]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43e17a8315csm144060261cf.32.2024.05.23.08.00.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 08:00:02 -0700 (PDT) Message-ID: <6fbc9a1e-fc3b-4034-a56d-3e8e64413b2c@citrix.com> Date: Thu, 23 May 2024 15:59:59 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/bhi: BHI mitigation can trigger warning in #DB handler To: Alexandre Chartre , x86@kernel.org, kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, daniel.sneddon@linux.intel.com, pawan.kumar.gupta@linux.intel.com, tglx@linutronix.de, konrad.wilk@oracle.com, peterz@infradead.org, gregkh@linuxfoundation.org, seanjc@google.com, dave.hansen@linux.intel.com, nik.borisov@suse.com, kpsingh@kernel.org, longman@redhat.com, bp@alien8.de, pbonzini@redhat.com, "Kaplan, David" References: <20240523123322.3326690-1-alexandre.chartre@oracle.com> <771bbaa3-0fa5-4b0a-a0a2-6516b4f42867@citrix.com> <5f064eb5-cabd-4adc-8c6f-6b2e449e3fe9@oracle.com> Content-Language: en-GB From: Andrew Cooper Autocrypt: addr=andrew.cooper3@citrix.com; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJt+cWwARAQABzSlBbmRyZXcgQ29v cGVyIDxhbmRyZXcuY29vcGVyM0BjaXRyaXguY29tPsLBegQTAQgAJAIbAwULCQgHAwUVCgkI CwUWAgMBAAIeAQIXgAUCWKD95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064eb5-cabd-4adc-8c6f-6b2e449e3fe9@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 23/05/2024 1:59 pm, Alexandre Chartre wrote: > > > On 5/23/24 14:42, Andrew Cooper wrote: >> On 23/05/2024 1:33 pm, Alexandre Chartre wrote: >>> diff --git a/arch/x86/entry/entry_64_compat.S >>> b/arch/x86/entry/entry_64_compat.S >>> index 11c9b8efdc4c..7fa04edc87e9 100644 >>> --- a/arch/x86/entry/entry_64_compat.S >>> +++ b/arch/x86/entry/entry_64_compat.S >>> @@ -91,7 +91,6 @@ >>> SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL) >>>         IBRS_ENTER >>>       UNTRAIN_RET >>> -    CLEAR_BRANCH_HISTORY >>>         /* >>>        * SYSENTER doesn't filter flags, so we need to clear NT and AC >>> @@ -116,6 +115,12 @@ >>> SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL) >>>       jnz    .Lsysenter_fix_flags >>>   .Lsysenter_flags_fixed: >>>   +    /* >>> +     * CLEAR_BRANCH_HISTORY can call other functions. It should be >>> invoked >>> +     * after making sure TF is cleared because single-step is >>> ignored only >>> +     * for instructions inside the entry_SYSENTER_compat function. >>> +     */ >>> +    CLEAR_BRANCH_HISTORY >> >> Exactly the same is true of UNTRAIN_RET, although it will only manifest >> in i386 builds running on AMD hardware (SYSENTER is #UD on AMD hardware >> in Long mode.) >> >> #DB is IST so does handle it's own speculation safety.  It should be >> safe to move all the speculation safety logic in the sysenter handler to >> after .Lsysenter_flags_fixed:, I think? >> > > Right, so something like this: > > --- a/arch/x86/entry/entry_64_compat.S > +++ b/arch/x86/entry/entry_64_compat.S > @@ -89,10 +89,6 @@ > SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL) >   >         cld >   > -       IBRS_ENTER > -       UNTRAIN_RET > -       CLEAR_BRANCH_HISTORY > - >         /* >          * SYSENTER doesn't filter flags, so we need to clear NT and AC >          * ourselves.  To save a few cycles, we can check whether > @@ -116,6 +112,15 @@ > SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL) >         jnz     .Lsysenter_fix_flags >  .Lsysenter_flags_fixed: >   > +       /* > +        * CPU bugs mitigations mechanisms can call other functions. They > +        * should be invoked after making sure TF is cleared because > +        * single-step is ignored only for instructions inside the > +        * entry_SYSENTER_compat function. > +        */ > +       IBRS_ENTER > +       UNTRAIN_RET > +       CLEAR_BRANCH_HISTORY Yeah - this looks rather better. Although I'd suggest a blank line here if you're going to formalise the patch. ~Andrew