Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1188800imu; Tue, 11 Dec 2018 14:25:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/XqRrfIKvc9Bm5vFPTPlofctl7t6OmQaX+qrnDMDqgzyZx/lqbDJcohIX3wDcXYXsR2U2Dl X-Received: by 2002:a17:902:bb05:: with SMTP id l5mr18032896pls.230.1544567156461; Tue, 11 Dec 2018 14:25:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544567156; cv=none; d=google.com; s=arc-20160816; b=mpoeQvwwea13CfoRShcOKK86PeU7IVjp5+BMjUJqnx6wp19gHS6i1XSTpAgbb/8luX OtG1uwFwyyLQj+NJyJ0SIg/F8XDlrILeQj1qyRJ2Oi0xSM3C5TbTn5fqemern0fS0/5R iAAFAAfvkuyVoK8Ea4iDCgs5yuv9gCYSOGzRvqdmcsoHydhjgu/yFI6LWfTmExsan0f4 C+0nMcqr2JaG1P4FVGLIDtyzPouDZZwT/npJN6r4qoE5X/wMAXwX41lSc1iQSXOC6MiN 6wE+eT4VOczGBqbi2mWkq9e9hbXNCGghgbT3IQHrTkK6sVxyALj1vlEzHtlx8Z635tbN fqlg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/mxEqfgkMMmGXETHhDRIDKT6kwIaVl8L4VY0yY4ghDM=; b=utcBHZi9AY7xAbMAj6X7EsEcZZcnsq5psIFyH6WeOx+1XiGA9MaKIHh5pOaZmwpfCH XttC0IMtAVtItosmlM/sXE/5kkX73ceo8Rs0ycd5SWQICnOTnUSMC1NysfbhAVhiDKy5 7gysen7Np43wGGtqri5GCKddMBkcR+2kJFuNJZOwTTZtrrgM1ePWbY83I0DMoDkybTi3 pubsMeePAGj2372nZAAkiHnEZRcWC7CfszB/oWhG4uWIAu6v26MJ2X8mDdmBv5QbptaT CBWnMPVe8ovR2ITJ1RID/8mn1gpSnLUhSBE/nzqVV2LISB8ryvfJ//K5HpIpB3N6svMb MWFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=WZ2lcHep; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m33si13216225pgl.379.2018.12.11.14.25.41; Tue, 11 Dec 2018 14:25:56 -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=@alien8.de header.s=dkim header.b=WZ2lcHep; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726371AbeLKWXg (ORCPT + 99 others); Tue, 11 Dec 2018 17:23:36 -0500 Received: from mail.skyhub.de ([5.9.137.197]:46246 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726343AbeLKWXd (ORCPT ); Tue, 11 Dec 2018 17:23:33 -0500 Received: from zn.tnic (p200300EC2BCD2B0010F6E1EC68D6BA6C.dip0.t-ipconnect.de [IPv6:2003:ec:2bcd:2b00:10f6:e1ec:68d6:ba6c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 08EF21EC0C0D; Tue, 11 Dec 2018 23:23:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1544567012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/mxEqfgkMMmGXETHhDRIDKT6kwIaVl8L4VY0yY4ghDM=; b=WZ2lcHepbhGEWdyW2m8JHf+gJ/R2h2YWHEgignzPNJWqchJs88iNwZC95VLdDJGYyiQqUn WSz40pUZhBDT4e82mt+fnaMW2DmpQW2SJzAU2OCFL6VlYb9ilQBCvQCUTfq7lul22F92ZB WYE4HquQFffpzUdHx4UbT5GyxlbLu+M= From: Borislav Petkov To: LKML Cc: X86 ML , Andy Lutomirski , "H. Peter Anvin" , Josh Poimboeuf , Peter Zijlstra , Tom Lendacky Subject: [RFC PATCH 3/4] x86/alternatives: Add an ALTERNATIVE_3() macro Date: Tue, 11 Dec 2018 23:23:25 +0100 Message-Id: <20181211222326.14581-4-bp@alien8.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181211222326.14581-1-bp@alien8.de> References: <20181211222326.14581-1-bp@alien8.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov Similar to ALTERNATIVE_2(), ALTERNATIVE_3() selects between 3 possible variants. Will be used for adding RDTSCP to the rdtsc_ordered() alternatives. Signed-off-by: Borislav Petkov --- arch/x86/include/asm/alternative.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 8d38b296a18a..f24d111f366b 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -115,6 +115,16 @@ static inline int alternatives_text_reserved(void *start, void *end) "(" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")), 0x90\n" \ alt_end_marker ":\n" +#define OLDINSTR_3(oldinsn, n1, n2, n3) \ + "# ALT: oldinstr3\n" \ + "661:\n\t" oldinsn "\n662:\n" \ + "# ALT: padding3\n" \ + ".skip -((" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \ + " - (" alt_slen ")) > 0) * " \ + "(" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3)) \ + " - (" alt_slen ")), 0x90\n" \ + alt_end_marker ":\n" + #define ALTINSTR_ENTRY(feature, num) \ " .long 661b - .\n" /* label */ \ " .long " b_replacement(num)"f - .\n" /* new instruction */ \ @@ -148,6 +158,19 @@ static inline int alternatives_text_reserved(void *start, void *end) ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \ ".popsection\n" +#define ALTERNATIVE_3(oldinsn, newinsn1, feat1, newinsn2, feat2, newinsn3, feat3) \ + OLDINSTR_3(oldinsn, 1, 2, 3) \ + ".pushsection .altinstructions,\"a\"\n" \ + ALTINSTR_ENTRY(feat1, 1) \ + ALTINSTR_ENTRY(feat2, 2) \ + ALTINSTR_ENTRY(feat3, 3) \ + ".popsection\n" \ + ".pushsection .altinstr_replacement, \"ax\"\n" \ + ALTINSTR_REPLACEMENT(newinsn1, feat1, 1) \ + ALTINSTR_REPLACEMENT(newinsn2, feat2, 2) \ + ALTINSTR_REPLACEMENT(newinsn3, feat3, 3) \ + ".popsection\n" + /* * Alternative instructions for different CPU types or capabilities. * -- 2.19.1