Received: by 10.223.176.5 with SMTP id f5csp1088980wra; Wed, 7 Feb 2018 12:28:20 -0800 (PST) X-Google-Smtp-Source: AH8x225hV3UXsqzXMtk3aPm3KbuEMwEJDbuuIvfj2v0LgMl1XACRfXN4jZyvtzLVxop5CwXjcGyU X-Received: by 2002:a17:902:fa2:: with SMTP id 31-v6mr7393526plz.346.1518035300585; Wed, 07 Feb 2018 12:28:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518035300; cv=none; d=google.com; s=arc-20160816; b=IomgGAxoWdsISeOJfl0+MiZJY+qnzAq/R+X2hhteSk2jX7tTTrSeKlgfOHrHRdWX3G phq6iNXL+sFWM+YSrcGhvxdoNZvJGKetCtoyCUztGx3PmVMnH08bOCuQ6uDYfOY0Mog9 dCgWYj15SPtROKebrYOHfR3B21zZevSZY/lmn06p5UXSp43viOMWNdBnafnpYXyYq9de h8RIS9wKJM8gMn1Vnf+S/fJZ6LRJRrhSpzB1p2ccy5DtItsbJd0CNkw8ChbGixgNjReP wqkjZXFVD8JtM3WAbKRVo9sp1c5QTft3DTnVqZbS8P4p55UJX0D+IouG4lxMa608rGBx 2SJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=GqDySMA7nhRhamG6rmUFnYGr2N8nUoNKSAPaIMyx0KU=; b=Rg58O7dERYznf0o2qj4TuaFbz4EyNp83ErnMnYxjv8TbVH8qb/4/I0E7wQK68cIYuv peN7JoSXlM+uWAdKYUnIeLTBQ8O6EruOixKU0dj25jnS3jkwG4nLNrIpJn/lw8xfmQ6W Gy2c3wlqDiQR8Kq/xHcpBucxSJBC5R8+2K1y+YGrTSsOe0IT/ZFglBMQUalvlF6YC4Ws EuMQHow6tDU69soP4UAfi8rvcSgk3cj9HC/ks6UYfjvDxZ6a4QPC0hPuqp21yhAcStKy cKsCKD68tWDK08zG8cvhF81p7rHn4FEam9AGgu1RN/QyOii9Tfgyi1w1dIFDqWip8Gju opIQ== ARC-Authentication-Results: i=1; mx.google.com; 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 q61-v6si1592298plb.183.2018.02.07.12.28.06; Wed, 07 Feb 2018 12:28:20 -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; 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 S1754572AbeBGU1L (ORCPT + 99 others); Wed, 7 Feb 2018 15:27:11 -0500 Received: from terminus.zytor.com ([65.50.211.136]:53603 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754397AbeBGU1J (ORCPT ); Wed, 7 Feb 2018 15:27:09 -0500 Received: from hanvin-desk.amr.corp.intel.com ([134.134.139.76]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id w17KK9ks023166 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 7 Feb 2018 12:20:10 -0800 Subject: Re: [RFC 0/3] x86: Patchable constants To: Linus Torvalds , "Kirill A. Shutemov" Cc: the arch/x86 maintainers , Tom Lendacky , Peter Zijlstra , Dave Hansen , Andy Lutomirski , Borislav Petkov , linux-mm , Linux Kernel Mailing List References: <20180207145913.2703-1-kirill.shutemov@linux.intel.com> From: "H. Peter Anvin" Message-ID: <8fea57cc-8772-f8b4-3298-91b0de126358@zytor.com> Date: Wed, 7 Feb 2018 12:20:09 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/07/18 09:01, Linus Torvalds wrote: > > Look - much smaller code, and register %rcx isn't used at all. And no > D$ miss on loading that constant (that is a constant depending on > boot-time setup only). > > It's rather more complex, but it actually gives a much bigger win. The > code itself will be much better, and smaller. > > The *infrastructure* for the code gets pretty hairy, though. > > The good news is that the patch already existed to at least _some_ > degree. Peter Anvin did it about 18 months ago. > > It was not really pursued all the way because it *is* a lot of extra > complexity, and I think there was some other hold-up, but he did have > skeleton code for the actual replacement. > > There was a thread on the x86 arch list with the subject line > > Disgusting pseudo-self-modifying code idea: "variable constants" > > but I'm unable to actually find the patch. I know there was at least a > vert early prototype. > > Adding hpa to the cc in the hope that he has some prototype code still > laying around.. > The patchset I have is about 85% complete. It mostly needs cleanup, testing, and breaking into reasonable chunks (it got put on the backburner for somewhat obvious reasons, but I don't think it'll take very long at all to productize it.) The main reason I haven't submitted it yet is that I got a bit overly ambitious and wanted to implement a whole bunch of more complex subcases, such as 64-bit shifts on a 32-bit kernel. The win in that case is actually quite huge, but it is requires data-dependent code patching and not just immediate patching, which requires augmentation of the alternatives framework. -hpa