Received: by 10.223.176.5 with SMTP id f5csp896767wra; Wed, 7 Feb 2018 09:13:49 -0800 (PST) X-Google-Smtp-Source: AH8x2279ONjeKQNfeyiixzVgCVGoEAo4EgSLKNQ1Pwbm7+sRx9C/qOUH1mYRrA0p3cLg+ftPoymg X-Received: by 2002:a17:902:8215:: with SMTP id x21-v6mr6718913pln.381.1518023629363; Wed, 07 Feb 2018 09:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518023629; cv=none; d=google.com; s=arc-20160816; b=VJ0bS56BAr+5L51XJ8hM3ziY/PDSGTwX4F7D8+WPU/kP7ChOlNpZjyjj5FAYWfuuQj cJwNbgkzzu6iwTjVBJgpR/vIJDygxSlUnL6wH5z15saQj2E1R28yXHOq3mEmR7+g9Kzn cNChE3oeqvL3sj45isr3zMnX6alwbKGtSBQT87ahOzlpVPj9ziklpjQ2gcnPBTG+f+r5 Ad4GEh7nqlsnSt0IohOum6YfWU23l8FkeIqi3DQhTAV3oR+nvvoNLGZQFrzuJkiDu0uX fyaa9WGbI4f3LpTYU8R1Tcl/gZnAPLZE00/nH8FhEL3ilOhju3iOqOs6r9L9aO3uNdB/ JXUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=9EP+YkHimhgVZeE5sycs4j5txMXyl1g0Z/ISSMJ5Isk=; b=egRfOmdkJhkQrnpEMigdgt9JOmPuNGcTm3do304srG6GbSWt3uLZyDDit/faewAs2+ UjScm8qcYOJDhkJt+5HRrcwBB/yfRT19DcobrIs1Nbqnt+TWbCKNhAp1uRyeSvYmwPlJ 82lcl4vxxzOB8KQyvHdeEuisGfl3f2wTF5Eq+m8dBPor70rGKuMDDlYA4Gh4T08KS8Jl CCtMsex7iEtPFh8ca7tsbk82bXs/MQWUMnXVP1VQumXamcfObjf0uQwf5s2yU+m4ty6P wk2VyW7mnwaY2vdp5T7G4v85ZMwIJq8w8J/fdxsfKSqh7liPbohWblimEUkxDzdQuQQY x/tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=piKcMWnL; 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 c21-v6si1361785plo.46.2018.02.07.09.13.35; Wed, 07 Feb 2018 09:13:49 -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=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=piKcMWnL; 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 S1754811AbeBGRMU (ORCPT + 99 others); Wed, 7 Feb 2018 12:12:20 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39325 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754463AbeBGRMS (ORCPT ); Wed, 7 Feb 2018 12:12:18 -0500 Received: by mail-wm0-f68.google.com with SMTP id b21so4740170wme.4 for ; Wed, 07 Feb 2018 09:12:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9EP+YkHimhgVZeE5sycs4j5txMXyl1g0Z/ISSMJ5Isk=; b=piKcMWnL+97o7JH3vyOeuGtMJxBZDpSVRxaI2pR7QIMPKKnNg+amtFcJie8uw5jZtW inRfBw/kj56yjo1YLnoxUIgcuxC8aM4nexhtuxPxrD+HxvW8jWbRoDMTs3/4uzfKpyf2 dlIWHgiQ1NNomv37zid0bN8T6Avcglh0TD8rmkmgPd90plm4Iby6p0WA0Ro8aIlT06Nl sAeNR+dcnHNhZSnEQFc697CnAoQBL3sFeT3kxPScGXCLW+40iwRvXYk9aKxDk7Ax37GH NhIExkykx+dzqdjbh0UyGm6TFOsnCqEIlDe9cU+luDBf87Oq+PSVfMfKoaeC2xuxuQL5 OjoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=9EP+YkHimhgVZeE5sycs4j5txMXyl1g0Z/ISSMJ5Isk=; b=dCx6TYbfqapf4K1DQvtAinxRoL7LQXzyv18SX9wj/hmwnvtD+ndl6GI0xgoqDYdNHY VrExo3Uccl1mf1JEzmxWa/Ed4LyFbQeEP0I3lREa4w4oIzrNSRdmkMaHIo+QXEAY3fZr nbFsef3gzJhoTEDFwJlxLeZhVf7HFgV82pnP9tjeBkUms92cNGDhPuM01aW2yyeZGCi3 DPLKiJlvPlkrSdNFgu1mNzKEGTo4HeKFroUbJ0+Np851l2uRfOwWivoWEetsMYeSsX6I aque8deDob7TeIguv2MeVO/sjVt6H8hbQjQV7oU96UhEpbQ0CF0lwQLRKNA7fMrQ74m0 8wzQ== X-Gm-Message-State: APf1xPAg1HIDWmTXBYZHCrn3lwse4zv5uoCRReFo3AA8s8JN/qmYPR7O HFqHcqC13HyTd+3hiIiBlw00YpKo X-Received: by 10.80.142.188 with SMTP id w57mr8816510edw.11.1518023537412; Wed, 07 Feb 2018 09:12:17 -0800 (PST) Received: from node.shutemov.name ([178.121.192.223]) by smtp.gmail.com with ESMTPSA id g7sm1325375edf.76.2018.02.07.09.12.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2018 09:12:16 -0800 (PST) Received: by node.shutemov.name (Postfix, from userid 1000) id AD62B648D520; Wed, 7 Feb 2018 20:12:15 +0300 (+03) Date: Wed, 7 Feb 2018 20:12:15 +0300 From: "Kirill A. Shutemov" To: Peter Zijlstra Cc: "Kirill A. Shutemov" , Linus Torvalds , x86@kernel.org, Tom Lendacky , Dave Hansen , Andy Lutomirski , Borislav Petkov , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC 0/3] x86: Patchable constants Message-ID: <20180207171215.b52hql2bv5wzff6o@node.shutemov.name> References: <20180207145913.2703-1-kirill.shutemov@linux.intel.com> <20180207162507.GB25219@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180207162507.GB25219@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 07, 2018 at 05:25:07PM +0100, Peter Zijlstra wrote: > On Wed, Feb 07, 2018 at 05:59:10PM +0300, Kirill A. Shutemov wrote: > > This conversion makes GCC generate worse code. Conversion __PHYSICAL_MASK > > to a patchable constant adds about 5k in .text on defconfig and makes it > > slightly slower at runtime (~0.2% on my box). > > Do you have explicit examples for the worse code? That might give clue > on how to improve things. Clarification: increase by 5k was for defconfig, where I replaced pure constant define __PHYSICAL_MASK with patchable constant. With CONFIG_AMD_MEM_ENCRYPT=y increase is smaller: ~1.8k. The disassembler below is for CONFIG_AMD_MEM_ENCRYPT=y. Before: Dump of assembler code for function migration_entry_wait: 0xffffffff8118ab40 <+0>: mov (%rsi),%rcx 0xffffffff8118ab43 <+3>: shr $0x9,%rdx 0xffffffff8118ab47 <+7>: mov 0x10aecba(%rip),%r8 # 0xffffffff82239808 0xffffffff8118ab4e <+14>: mov %rdx,%rax 0xffffffff8118ab51 <+17>: mov 0x10aec90(%rip),%r9 # 0xffffffff822397e8 0xffffffff8118ab58 <+24>: movabs $0x3fffffe00000,%rsi 0xffffffff8118ab62 <+34>: and $0xff8,%eax 0xffffffff8118ab67 <+39>: test $0x80,%cl 0xffffffff8118ab6a <+42>: not %r8 0xffffffff8118ab6d <+45>: jne 0xffffffff8118ab79 0xffffffff8118ab6f <+47>: movabs $0x3ffffffff000,%rsi 0xffffffff8118ab79 <+57>: and %r8,%rsi 0xffffffff8118ab7c <+60>: add 0x10aec75(%rip),%rax # 0xffffffff822397f8 0xffffffff8118ab83 <+67>: and %rsi,%rcx 0xffffffff8118ab86 <+70>: mov %rcx,%rdx 0xffffffff8118ab89 <+73>: shr $0x6,%rdx 0xffffffff8118ab8d <+77>: mov %rax,%rsi 0xffffffff8118ab90 <+80>: lea 0x30(%r9,%rdx,1),%rdx 0xffffffff8118ab95 <+85>: add %rcx,%rsi 0xffffffff8118ab98 <+88>: jmpq 0xffffffff8118aa20 <__migration_entry_wait> After: Dump of assembler code for function migration_entry_wait: 0xffffffff8118b3e0 <+0>: mov (%rsi),%rsi 0xffffffff8118b3e3 <+3>: mov %rdx,%rax 0xffffffff8118b3e6 <+6>: mov 0x10ae41b(%rip),%r8 # 0xffffffff82239808 0xffffffff8118b3ed <+13>: shr $0x9,%rax 0xffffffff8118b3f1 <+17>: and $0xff8,%eax 0xffffffff8118b3f6 <+22>: test $0x80,%sil 0xffffffff8118b3fa <+26>: jne 0xffffffff8118b432 0xffffffff8118b3fc <+28>: mov %rsi,%rdx 0xffffffff8118b3ff <+31>: movabs $0x3fffffffffff,%rcx 0xffffffff8118b409 <+41>: and %rcx,%rdx 0xffffffff8118b40c <+44>: and $0xfffffffffffff000,%rcx 0xffffffff8118b413 <+51>: shr $0xc,%rdx 0xffffffff8118b417 <+55>: shl $0x6,%rdx 0xffffffff8118b41b <+59>: lea 0x30(%r8,%rdx,1),%rdx 0xffffffff8118b420 <+64>: add 0x10ae3f1(%rip),%rax # 0xffffffff82239818 0xffffffff8118b427 <+71>: and %rcx,%rsi 0xffffffff8118b42a <+74>: add %rax,%rsi 0xffffffff8118b42d <+77>: jmpq 0xffffffff8118b2c0 <__migration_entry_wait> 0xffffffff8118b432 <+82>: mov %rsi,%rdx 0xffffffff8118b435 <+85>: and $0xffffffffffe00000,%rdx 0xffffffff8118b43c <+92>: movabs $0x3fffffffffff,%rcx 0xffffffff8118b446 <+102>: and %rcx,%rdx 0xffffffff8118b449 <+105>: and $0xffffffffffe00000,%rcx 0xffffffff8118b450 <+112>: shr $0x6,%rdx 0xffffffff8118b454 <+116>: lea 0x30(%r8,%rdx,1),%rdx 0xffffffff8118b459 <+121>: jmp 0xffffffff8118b420 -- Kirill A. Shutemov