Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1099455imm; Fri, 5 Oct 2018 18:41:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV63NFngsUBNku0p335tFIJBhBnUVH3IYgpTaIdRN3iKmpvr4DXrbc6+GISkYpa79T2VWCuS2 X-Received: by 2002:a63:d14a:: with SMTP id c10-v6mr12402249pgj.384.1538790062142; Fri, 05 Oct 2018 18:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538790062; cv=none; d=google.com; s=arc-20160816; b=WamZeRM1gSE0O9acgYwPaawltr2uCizUaGdB95yfQRmCJVZHqrcRVYY0hPxLzM8R+M sdzx71B4Exq9djVGDN8fxF/PK00ItagFieXSU/Mig4Aq75P6NhbMJO1enO5Ek+Ej2GVC cMxibZQIr6telEdQLQDSUfZXTGzdzQ8dwYP+2pTSP2mcqyTLRje3XM5BWuwAzla7oPgC 8UTw7Y602RtY7pLxwueyj39Wyu0p2OQjct/ZUXRmpRCJDb93QMbKscSPNqX4CcT3U5NL MuoUVXm++cmbEf2ciRANF0G7U6dX/1oowb5p9fkXXORhN911T6f9VDz81PM5uHf9mG6f a+mw== 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:dkim-signature; bh=yI7XQyg/f4gf3BQBzbr8fAnSSZ5R3RfZyAjZBppbxUs=; b=IloJ2gLhlq6Ph+aipCxBQUhUdqxa8Pgt7JKi4Pa6eRzFJ0glvkCgNNzlU93gC1mUpx heNJ+u23C+p/EAepND+QaIVnJ5cOVRQJbxutBj56Eg5jv12yeJtr6Q0a7CAgA0YK5CDX l7qMLBivcJfipdC9Il3pSJdDxqHb5LKDs6II9FfvMqM3yyEmSQ5JU810BTiD84vZ7YM/ xfHlCbS+8x6GMjwCn43+soV7H+FqfBrIaJP6vaiHICqTuYAm3Owrlq6FS4ITyJ/4JwIO A2R/Ox5xy6fwyyVU1FjCZmwE43YLYwYJAFIZt/xKby5UuMG+9WzpA6ygamnDLAkgf/3G IzUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=GvDQD7Pr; 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 z2-v6si9960926pgb.247.2018.10.05.18.40.33; Fri, 05 Oct 2018 18:41:02 -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=@rasmusvillemoes.dk header.s=google header.b=GvDQD7Pr; 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 S1728718AbeJFIlv (ORCPT + 99 others); Sat, 6 Oct 2018 04:41:51 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36966 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbeJFIlu (ORCPT ); Sat, 6 Oct 2018 04:41:50 -0400 Received: by mail-ed1-f67.google.com with SMTP id c22-v6so13125321edc.4 for ; Fri, 05 Oct 2018 18:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=yI7XQyg/f4gf3BQBzbr8fAnSSZ5R3RfZyAjZBppbxUs=; b=GvDQD7PryO0QH/Kd01NmYyscWGF79P91k74YZwvuTGBz0LdD/TuFxjLoyF4QdEuw14 L3Fq/JyV42C+DEYXMe/2WBsZ0CwuHk2/+SSV0XUJOpli0MbWu8PTSntu5FurcDbZB9x1 OYzaxVY/GJH5XY32lpSU0cM8dlWaAHhb7XdJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yI7XQyg/f4gf3BQBzbr8fAnSSZ5R3RfZyAjZBppbxUs=; b=GEOGJ3iPMNkljFI+tBUmaw9VjI3s5aXA5paYq+q1hOERdAHYtsv1FAbuLY6Q5o1Dyk xxacut/ctdOhmN7Hm0ReAl8V76Im8ELQhlP6IiTlMKU4sEdV3/srXlOaGnn+GLG0/PBB kdFEAgXBJ+1VxlY+VADCRaT7HUHnzuXA0eo9yMbmG4opDBzF1/MO4g8POUorAC1H/Y6H QKr3yDfaWP2nAtRgBIiEHG5l3jmLM63EeywzBbnfweQxu8k9edw7Ir8OVbFVf3oKzOhD U8KlWPo9y1ojkDnVllg98Ghc6lOeo5qNaenxqcpA+cnrTjh/We0Rm2GZbOAqN5XC/bAi f5PA== X-Gm-Message-State: ABuFfohgEe6oH96Y9m2Gy2s22hIejSkO98NGupzXHadgTBUtoultN6I9 RyoE/MfeIfHSG3+8CMKLP8AMqg== X-Received: by 2002:a50:b941:: with SMTP id m59-v6mr17246313ede.20.1538790027610; Fri, 05 Oct 2018 18:40:27 -0700 (PDT) Received: from [192.168.0.189] (dhcp-5-186-116-96.cgn.ip.fibianet.dk. [5.186.116.96]) by smtp.gmail.com with ESMTPSA id n41-v6sm3033811edd.7.2018.10.05.18.40.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Oct 2018 18:40:26 -0700 (PDT) Subject: Re: [PATCH v9 04/10] x86: refcount: prevent gcc distortions To: "H. Peter Anvin" , Ingo Molnar Cc: Nadav Amit , Ingo Molnar , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , Thomas Gleixner , Jan Beulich , Josh Poimboeuf , Linus Torvalds , Peter Zijlstra , Andy Lutomirski References: <20181003213100.189959-1-namit@vmware.com> <20181003213100.189959-5-namit@vmware.com> <20181004075755.GA3353@gmail.com> <20181004083333.GA9802@gmail.com> <10D29A50-C352-4407-A824-0C3C06CD8592@zytor.com> <36D6F606-6922-4057-B1F8-2B30993962AE@zytor.com> <20181004091651.GB21151@gmail.com> From: Rasmus Villemoes Message-ID: <85bef695-f7af-0e77-9790-6a6965b9d02b@rasmusvillemoes.dk> Date: Sat, 6 Oct 2018 03:40:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 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 2018-10-04 21:33, H. Peter Anvin wrote: > Here is the horrible code I mentioned yesterday. This is about > implementing the immediate-patching framework that Linus and others have > discussed (it helps both performance and kernel hardening): Heh, I did a POC in userspace some years ago for loading an "eventually constant" value into a register - the idea being to avoid a load in cases like kmemcache_alloc(foo_cachep) or kmemcache_free(foo_cachep, p), and I assume this is something along the same lines? I didn't do anything with it since I had no idea if the performance gain would be worth it, and at the time (before __ro_after_init) there was no good way to know that the values would really be constant eventually. Also, I had hoped to come up with a way to avoid having to annotate the loads. I just tried expanding this to deal with some of the hash tables sized at init time which I can see was also mentioned on LKML some time ago. I'm probably missing something fundamental, but there's some sorta working code at https://github.com/villemoes/rai which is not too horrible (IMO). Attaching gcc at various times and doing disassembly shows that the patching does take place. Can I get you to take a look at raimacros.S and tell me why that won't work? Thanks, Rasmus