Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp765266pxa; Wed, 5 Aug 2020 12:12:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaJJsmuMdaBllH75ShS1tDu6LgwjIqNqRMB4ofyjVRammwFMXygHs0rVF2AX1Zm7KyDkGU X-Received: by 2002:a05:6402:a4c:: with SMTP id bt12mr699582edb.360.1596654737391; Wed, 05 Aug 2020 12:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596654737; cv=none; d=google.com; s=arc-20160816; b=BhuVtd7GtinS3TsfLaR3jjZSfWZrvRyWxEz02NbpEJPph9KcqOde6KwTM60U1bmHo+ rUGwSnvL3OMdKpyg+vS7sHhd3/pup22cqfPqfyayY4UOB4qjGjIKUPtIXwWbFA8AB+NR rkpd0s48yl1B2yYdvA2L/CNBBjlM0Kvexs25e1x6+OoSH3Xu2eDXgqyX6STj/N3bhrR8 x0Ez4E4s/FH9m3jXvyhSnkVVG9KnW4HujEdJpUeS0eN02phk4o6Hi9Gw7f96z/7A1gkG /p2Mr1pPCSbgvyMJRRbVofwvaLvWe/y6ShQDfj5Mt2OnUgMqAX7/qGU73BJVgLMfVkOJ ByBA== 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=O+UBUlbvu43CJ5x4ddBwzjAMx4kwZSPk4Ywzjmda1YI=; b=r/u4YOwYNaSOnkCLc32o5KO66F4BYfuH/NdB3nQ3TKaxCXQwm3eNz1PRBbvHFwH1U2 /trP/+zYLIJjStj2YA6alLy/jVb2GObH8T/+GucFJfCdOfT70WH2Sxr46NIv6z7BnrOa P/BDdx0uxhxS3y68cTfM/x2kNxepa41UHvQACtdxW/stYXTkzluFHzymvwc0ptq/MiJr e7KyPkHnCnsCpwCZs13tMxdV2vBsaq8YWIeb0IS2pA45yB1eGkDaRGD9apmAsei/z+eU 8g74Dh+jBzjpPxRyjLuivlUAIdbLwbnsRqlkikUS0sO34J/SVsQPGhPO9XeSrTkW4lfQ ICDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VWPAwtdo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w22si562089eju.155.2020.08.05.12.11.51; Wed, 05 Aug 2020 12:12:17 -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=@kernel.org header.s=default header.b=VWPAwtdo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728795AbgHETLX (ORCPT + 99 others); Wed, 5 Aug 2020 15:11:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:35400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729251AbgHESaU (ORCPT ); Wed, 5 Aug 2020 14:30:20 -0400 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CABB22310D for ; Wed, 5 Aug 2020 18:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596652126; bh=+orqcmMUx4wxaMB9/tQ3uZegiQO+qPJJ8gk9VLAh5zc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VWPAwtdomtPlOEYpApBm0RJG0+rh5r5Fx6XZ7HhNy56z9KhVhQ9Q4O9yNsyuWKfM3 biIAcbAYb9keWj8iPDEVluOBvymJypjy5yMPc/tXmThUkWpgMrjfKPNsIEcmvNz30e HKF/N21EFPS49yM7wvprq2QV5B7AXUzGdVKaFIa4= Received: by mail-wr1-f41.google.com with SMTP id a14so41653413wra.5 for ; Wed, 05 Aug 2020 11:28:45 -0700 (PDT) X-Gm-Message-State: AOAM532jIxThxBCv5u49u+nWP2w3HayZjdOakg+s/d5r08bkfCtSavEN 48OdR693fTeYBjwjGC3Vaj5bR8EdLPkKdQVp9eo8NA== X-Received: by 2002:a5d:65d2:: with SMTP id e18mr3831077wrw.70.1596652124048; Wed, 05 Aug 2020 11:28:44 -0700 (PDT) MIME-Version: 1.0 References: <20200805021059.1331-1-ricardo.neri-calderon@linux.intel.com> <20200805044840.GA9127@nazgul.tnic> <47A60E6A-0742-45FB-B707-175E87C58184@zytor.com> <20200805050808.GC9127@nazgul.tnic> <20200805170717.GB26661@ranerica-svr.sc.intel.com> In-Reply-To: <20200805170717.GB26661@ranerica-svr.sc.intel.com> From: Andy Lutomirski Date: Wed, 5 Aug 2020 11:28:31 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] x86/cpu: Use SERIALIZE in sync_core() when available To: Ricardo Neri Cc: Borislav Petkov , "H. Peter Anvin" , Borislav Petkov , Thomas Gleixner , Ingo Molnar , Andy Lutomirski , X86 ML , "Peter Zijlstra (Intel)" , Dave Hansen , Tony Luck , Cathy Zhang , Fenghua Yu , Kyung Min Park , "Ravi V. Shankar" , Sean Christopherson , LKML , Ricardo Neri , Dave Hansen , linux-edac 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, Aug 5, 2020 at 10:07 AM Ricardo Neri wrote: > > On Wed, Aug 05, 2020 at 07:08:08AM +0200, Borislav Petkov wrote: > > On Tue, Aug 04, 2020 at 09:58:25PM -0700, hpa@zytor.com wrote: > > > Because why use an alternative to jump over one instruction? > > > > > > I personally would prefer to have the IRET put out of line > > > > Can't yet - SERIALIZE CPUs are a minority at the moment. > > > > > and have the call/jmp replaced by SERIALIZE inline. > > > > Well, we could do: > > > > alternative_io("... IRET bunch", __ASM_SERIALIZE, X86_FEATURE_SERIALIZE, ...); > > > > and avoid all kinds of jumping. Alternatives get padded so there > > would be a couple of NOPs following when SERIALIZE gets patched in > > but it shouldn't be a problem. I guess one needs to look at what gcc > > generates... > > But the IRET-TO-SELF code has instruction which modify the stack. This > would violate stack invariance in alternatives as enforced in commit > 7117f16bf460 ("objtool: Fix ORC vs alternatives"). As a result, objtool > gives warnings as follows: > > arch/x86/kernel/alternative.o: warning: objtool: do_sync_core()+0xe: > alternative modifies stack > > Perhaps in this specific case it does not matter as the changes in the > stack will be undone by IRET. However, using alternative_io would require > adding the macro STACK_FRAME_NON_STANDARD to functions using sync_core(). > IMHO, it wouldn't look good. > > So maybe the best approach is to implement as you suggested using > static_cpu_has()? I agree. Let's keep it simple. Honestly, I think the right solution is to have iret_to_self() in actual asm and invoke it from C as needed. IRET is *slow* -- trying to optimize it at all is silly. The big optimization was switching from CPUID to IRET, since CPUID is slooooooooooooooooooow in virtual environments, whereas IRET is merely sloooooooow and SERIALIZE is probably just sloooow. (I once benchmarked it. IIRC the winning version on my laptop is MOV to CR2 on bare metal and IRET in a Xen PV guest. This optimization was not obviously worthwhile.) > > Thanks and BR, > Ricardo