Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp937253ybs; Mon, 25 May 2020 03:05:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUgmSx/uQGQwb6OV9k0kyITM2GixKzKkPlHXZOHqNtuu4ExmzXbRWTvMVP3EuaXLxfMEUR X-Received: by 2002:a17:906:c29a:: with SMTP id r26mr17740469ejz.286.1590401121738; Mon, 25 May 2020 03:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590401121; cv=none; d=google.com; s=arc-20160816; b=Lf1vtoYarPHp+HExwdtBctpf5Ulhk5hPBHA/NjpUM4jXllHH4UYAsLF0V7bstPGxb8 2vo0e8gA8xELB6JFjKgVGlRDkFI0tkUFCR67ZU77lefJ2aecDnx+wCLWAcZaj3zpLSYC eIKp2Fqz7sdUleuqD0MR8JxAVr0jELWCikTGWMGlF9ufjmWRp2xKWf5GhWrYhzfmyVgY P9aIa1sxLLasvRu/PRN7Pjq+Enw66PhFYJ/pScZq/FSMEV8GiCkoxf72eUhLbxjLNWtd 6r/qqZpoSvLNGRnSCA6eRnuW/cBzHSaCuvYJr/1Z19ZjZKH/8yU4kyHu6YiTtcHETqP8 SDjg== 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=6JDfobSYqsyyu/D04lt0P9nNu2ecR7qiHqjNJohMlNY=; b=aiyMs2s+DnpZVMvvAaNMDbmLQIkjlo30MZR4ZuFnxqYdr6rqw6JaFTVrW1Xs9AI+w/ Vt0xbg6qWgfeanCpERqpRmxiajI4K+hewq9QG7YvY2AdQi600M8rPqEzsTogLHCHJDml 674Sciv/OQ8uQ4hHYIxC+M3hoPmtjleVTmzNQMpJQ8A64iO1ynMH3/FBZzkc2ZlMpMEc +XDRJxSgMZa/ivKXbFCRfy6EspvjFhZJSXHt4VvZGygEa95MAFczdB7EwDLCppQbOZbE AMTDM+hp5EesFtDc/qONdcgDNfBzN2aMaRkor9aUaFIwUN6V5UjhjuanGQJhnG35gIoF pYNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=b580WbuQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e4si9240708edm.144.2020.05.25.03.04.57; Mon, 25 May 2020 03:05:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=b580WbuQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389678AbgEYKCx (ORCPT + 99 others); Mon, 25 May 2020 06:02:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389398AbgEYKCw (ORCPT ); Mon, 25 May 2020 06:02:52 -0400 Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD476C061A0E for ; Mon, 25 May 2020 03:02:51 -0700 (PDT) Received: by mail-ej1-x641.google.com with SMTP id x1so19897448ejd.8 for ; Mon, 25 May 2020 03:02:51 -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=6JDfobSYqsyyu/D04lt0P9nNu2ecR7qiHqjNJohMlNY=; b=b580WbuQio33Ps4e9L5AU+KV1wNrHDvSj3P7VUMr67ZaY1yZjpzIbAVBTvJ/Tk5IFP 1tnDzoH8kmqk8Kh/oRxWch+baMdtU7/Z/MUuMIA82bhJtoRyBpuQLB7NtYahUK0ALJFh fEmWHjzKhN0EHWI+coRlbD1JAiWnGem/TR0cE= 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=6JDfobSYqsyyu/D04lt0P9nNu2ecR7qiHqjNJohMlNY=; b=uWcs/qNJlUjD9QES3wvyNVtHV2Cc0bvW2RfHuEgQOZkWlVdNL9OVtsPm0GyqxwxA2K dxIFpXyed5q9EraZee0cRKP3tHF2Lb5kYgy0F++4a6jr8VV0dy4yfJnm9ZctFx1Y4e/v lU8g/3V8m4yIj9Nwz+V8w92jK5NGkKKu1VogwqCBZfVswu6SPG6qpjldeWcboehlk1Zr lRD23jga3m2+ZOGDfyAOl+HmLg8ncwlOZlNG44fTWLFPSgByvQpCOHxOJTe6LAL4ikkO wEfPlIKDMSio6dwoFuSkwwLvX/w6vHs2KGk6kgAYUG0zGLSaRD/7UDIABEsY2O3cCnaF oE3A== X-Gm-Message-State: AOAM533XSftntIx8sPqywiVFD/YG4pH0xRXUWYkCBpErZvVPiNhe1RJx wKuza/L1FCGPTPd/YCnGs7ZE7lfIN08= X-Received: by 2002:a17:906:6841:: with SMTP id a1mr18675793ejs.271.1590400970458; Mon, 25 May 2020 03:02:50 -0700 (PDT) Received: from [192.168.1.149] (ip-5-186-116-45.cgn.fibianet.dk. [5.186.116.45]) by smtp.gmail.com with ESMTPSA id y66sm7684552ede.24.2020.05.25.03.02.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 May 2020 03:02:49 -0700 (PDT) Subject: Re: [RFC][PATCH 0/4] x86/entry: disallow #DB more To: Peter Zijlstra , Andy Lutomirski Cc: Thomas Gleixner , LKML , X86 ML References: <20200522204738.645043059@infradead.org> <20200523125940.GA2483@worktop.programming.kicks-ass.net> <20200523213235.GB4496@worktop.programming.kicks-ass.net> From: Rasmus Villemoes Message-ID: Date: Mon, 25 May 2020 12:02:48 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200523213235.GB4496@worktop.programming.kicks-ass.net> Content-Type: text/plain; charset=windows-1252 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 23/05/2020 23.32, Peter Zijlstra wrote: > On Sat, May 23, 2020 at 02:59:40PM +0200, Peter Zijlstra wrote: >> On Fri, May 22, 2020 at 03:13:57PM -0700, Andy Lutomirski wrote: > >> Good point, so the trivial optimization is below. I couldn't find >> instruction latency numbers for DRn load/stores anywhere. I'm hoping >> loads are cheap. > > + u64 empty = 0, read = 0, write = 0; > + unsigned long dr7; > + > + for (i=0; i<100; i++) { > + u64 s; > + > + s = rdtsc(); > + barrier_nospec(); > + barrier_nospec(); > + empty += rdtsc() - s; > + > + s = rdtsc(); > + barrier_nospec(); > + dr7 = native_get_debugreg(7); > + barrier_nospec(); > + read += rdtsc() - s; > + > + s = rdtsc(); > + barrier_nospec(); > + native_set_debugreg(7, 0); > + barrier_nospec(); > + write += rdtsc() - s; > + } > + > + printk("XXX: %ld %ld %ld\n", empty, read, write); > > > [ 1.628125] XXX: 2800 2404 19600 > > IOW, reading DR7 is basically free, and certainly cheaper than looking > at cpu_dr7 which would probably be an insta cache miss. > Naive question: did you check disassembly to see whether gcc threw your native_get_debugreg() away, given that the asm isn't volatile and the result is not used for anything? Testing here only shows a "mov %r9,%db7", but the read did seem to get thrown away. Rasmus