Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp804113ybl; Wed, 29 Jan 2020 09:58:17 -0800 (PST) X-Google-Smtp-Source: APXvYqwoCHKsii3FEbgFS9dc98+REDSVqMwdk0wTdi8HdBY+BY+PACSh4HK8Fv8zKBoSRIzSQ0FF X-Received: by 2002:a05:6808:4c2:: with SMTP id a2mr83523oie.118.1580320697611; Wed, 29 Jan 2020 09:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580320697; cv=none; d=google.com; s=arc-20160816; b=zPtZ6yu610ICmLRMVXPT9phx9Zia/OjRkQLHcUh8ou7MXbPNb2tfDkfLMJInCNjjSY jaCqkGSWFPJGLxvMbjd/nlmbz9MsjVStcTMSXA4Rya7iUOs8y6GNSs2oYralTM9mePpm tSP+s80r1bHxSCkQyLWevrUGmgu9NvPf7haWxFnAn+vUJpNnxWb9a90Ymum9GTDPOJsO LNKvuDeIdWSGdY/ol1PfJjkq0OmJ4zjUJ7XCrupV0wzvpwbygqeriok/qY0JxAUX6ZVv 9l9JPXk5b9g3HOtWuckP4afq6KXkFFIpIeMsRH/QTt9Fkt1ewN8/BPaugcq5e7mxRGKy rsmA== 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=pzs29JuQG9++PU2+nVCtLhiO0+B6uu2BSoJd1SQI/+8=; b=kjU0u3zX4gQxbNPuGWr3NUXWHdjdkMGW1m0vRKxufZSONMYXqX5IxihxKWuB+AumRq GpvtOo0QhV+qwXPOZ2lS9pBEBrAOr4EUBfal1A8dW9snB4GjKghGhWdvpQbFCbLWPk2F BxtCQ0fs56ZAka3y2b/fHJVz1ENpsl1vS20TToqhUqXcywqOu1kRCoeuw832uvCbVC4s jjMLRg0GjhgLbnmZcvm9oVdBcxlfo1EwEKfkVCbM7osgOZ9efxOmZmBd/gff2kiCr7Pk hYy0Cmb3Y1W17zVi0y1ftP71l6tbmKNCNZs7Dam/MjfRrdVU3/JSfLAqdfSiYJ+VlGx7 NRrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=ZDNjBOoo; 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 x137si1391175oif.42.2020.01.29.09.58.05; Wed, 29 Jan 2020 09:58:17 -0800 (PST) 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=@linux-foundation.org header.s=google header.b=ZDNjBOoo; 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 S1727355AbgA2RlU (ORCPT + 99 others); Wed, 29 Jan 2020 12:41:20 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37384 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726679AbgA2RlU (ORCPT ); Wed, 29 Jan 2020 12:41:20 -0500 Received: by mail-lj1-f194.google.com with SMTP id v17so268315ljg.4 for ; Wed, 29 Jan 2020 09:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pzs29JuQG9++PU2+nVCtLhiO0+B6uu2BSoJd1SQI/+8=; b=ZDNjBOoofmM2bds+jVfTEyLsLeyDbhxcaAyiKBnrSn4Xan7211Upqh8nXpEeFDwuyf IddxBvFqfzrjXn57FCei7ld78d8HXdBDP59mRVWlDUrlx9QRuZC3pUiGXrWG+zWw+K6Y s6j6nsO7YVwFHN8zWZDB8QmMfJDQ41htP6RlU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pzs29JuQG9++PU2+nVCtLhiO0+B6uu2BSoJd1SQI/+8=; b=kz78aJnMZKbuTi8KEQOfoI7XbeBeodJXqzzc+VxAViOFJ2jkBnkv29x7ePilvUxq09 d8/Egp0kdlSf5kyYBHw83t5I2QkH6wD4xMRPDU7NEsnHXNd6L/knUMoaKRKuCQrJgeKS vJrKij5VeifD+wuN+yp0K/0WJdq5W5m2SeX3si/947yP2go3Fk5G8Otb6WJ/k4vnBtNu 1sKWApXPlSpJLALWXJaxoU7tiGuqiNTg1yIrgexLffxpFb1E3t+wdHWTGKF2s/X6n/Wb 4IJ509P5gF9ZAqI7agc9i71iwfWe4sMsE09RvL6H6+mUSrDqO9JoVWxl3dQKaJ3GklNY KndQ== X-Gm-Message-State: APjAAAWPcr5pQFAUvKIbv80eJpYC/BjSSiZ7RQgMVBnr9Vc3XpaYg6Nb ZwrvDiggqJx80PU7Fus9qkrqtY9o1U0= X-Received: by 2002:a2e:b4cf:: with SMTP id r15mr181057ljm.52.1580319676414; Wed, 29 Jan 2020 09:41:16 -0800 (PST) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com. [209.85.167.41]) by smtp.gmail.com with ESMTPSA id d24sm1336093lja.82.2020.01.29.09.41.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jan 2020 09:41:15 -0800 (PST) Received: by mail-lf1-f41.google.com with SMTP id n25so308807lfl.0 for ; Wed, 29 Jan 2020 09:41:14 -0800 (PST) X-Received: by 2002:a05:6512:78:: with SMTP id i24mr256499lfo.10.1580319674390; Wed, 29 Jan 2020 09:41:14 -0800 (PST) MIME-Version: 1.0 References: <20200128165906.GA67781@gmail.com> <20200129132618.GA30979@zn.tnic> <20200129170725.GA21265@agluck-desk2.amr.corp.intel.com> In-Reply-To: <20200129170725.GA21265@agluck-desk2.amr.corp.intel.com> From: Linus Torvalds Date: Wed, 29 Jan 2020 09:40:58 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [GIT PULL] x86/asm changes for v5.6 To: "Luck, Tony" Cc: Borislav Petkov , Ingo Molnar , Linux Kernel Mailing List , Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Andrew Morton 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 Wed, Jan 29, 2020 at 9:07 AM Luck, Tony wrote: > > This returns "3" ... not what we want. But swapping the ERMS/FSRM order > gets the correct version. That actually makes sense, and is what I suspected (after I wrote the patch) what would happen. It would just be good to have it explicitly documented at the macro. > > And yes, your idea makes sense to use ALTERNATIVE_2 but as it is, it > > triple-faults my guest. I'll debug it more later to find out why, when I > > get a chance. > > Triple fault is a surprise. As long as you have ERMS, it shouldn't > hurt to take the FSRM code path. > > Does the code that performs the patch use memmove() to copy the alternate > version into place? That could get ugly! That would be bad indeed, but I don't think it should matter particularly for this case - it would have been bad before too. I suspect there is some other issue going on, like the NOP padding logic being confused. In particular, look here, this is the alt_instruction entries: altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b where the arguments are "orig alt feature orig_len alt_len pad_len" in that order. Notice how "pad_len" in both cases is the padding from the _original_ instruction (142b-141b). So what happens when all the three alternatives are different sizes? In particular, we have (a) first 'orig' with 'orig_pad' (b) then we do the first feature replacement, and we use that correct original padding (c) then we do the _second_ feature replacemement - except now 'orig_len, pad_len' doesn't actually match what the code is, because we've done that first replacement. I still don't see why it would be a problem, really, because the two replacement sequences don't actually care about the padding (they both end with a 'ret', so you don't need to get the padding nops right), but I wonder if this casues confusion. I do note that all the existing uses of ALTERNATIVE_2 in asm code that might have this issue (REP_GOOD vs ERMS) has an empty instruction in the middle, and the final instruction is the same size as the original. So _if_ there is some padding confusion in alternatives handling, it might easily have been hidden by that. So I'm just hand-waving. Maybe there was some simpler explanation (like me just picking the wrong instructions when I did the rough conversion and simply breaking things with some stupid bug). Linus