Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2027615imm; Thu, 24 May 2018 04:46:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKOXzua1njxziidF5tZqd9p1KXUidcXhhuXssV+8fKX1nAUKA5nq7l7bVCIwNtbw3r3yD1 X-Received: by 2002:a65:6285:: with SMTP id f5-v6mr5722825pgv.252.1527162369538; Thu, 24 May 2018 04:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527162369; cv=none; d=google.com; s=arc-20160816; b=NusZmHNVTBtw/o1QQF6kulu4xUB5uxxYYg9wdHbAtvhGypPS+0h3O9oy0U+dLfwJVc SZVZwPN6QCKa4G1MOxlM7x0JB6PSCe1H/9PdEm2JB32yA4i3aMvccsS/geuei9JKz+Gs n4+YtTFlgQgfa0pPdi6/8iHbY8a0fuD2uxw1jE/BHUhUj0OnPki/eiNMQP6O6PazSxS/ Jpotz9AVJnQF3n1GboH/3qK/K8f0ypDiBuRt8AglhLFkPI8eQMqPsNP6C2tMWa41Y/MJ pmw75Te/WBTlL4ZCgbV7qAJpaZh3RVEJk6BGrZ/z6WeH9Erv+b2MxjBM1OWffTseHHAc siWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=48eJ/WPgN7yGqqYRdWj6aIL5M9YWOTZkPwcFr+jFyL8=; b=QDZAYxx9zfdS76B7TRRbsoS8I2YHsey37lzmYd5SrGm3Ie9f+FaB/s6IVESRaIyxWc aYrnuyHYEpMtYxde61DJsVZKYEATieazeE7vhfp1LiYzQxtsSR9+8SCxVq0SVeTsTN2P CJtsA8HGfW3iyfgWthGK+NUDb140h6wPiAEuk8I/Vz9PmVdCP5ziOvX7F4OyoDyE5bsc C9YNceVJGRvdyR6bgE3eGEKot7KjmnZ7ybzrQu812KI4w2ZdI9EJgmSNA+zNhyVmVpBc e0RJNInIrBI95B91twpSqVxd1fHO0Qtt1p9toHtTz2DtKXDzo13J3+qKbbzvRqoZAq2W Xmsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UGlEc9h6; 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 43-v6si21666555pla.509.2018.05.24.04.45.54; Thu, 24 May 2018 04:46:09 -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=@kernel.org header.s=default header.b=UGlEc9h6; 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 S969323AbeEXLpE (ORCPT + 99 others); Thu, 24 May 2018 07:45:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:32962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967163AbeEXJsD (ORCPT ); Thu, 24 May 2018 05:48:03 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0DAD720847; Thu, 24 May 2018 09:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155282; bh=0O7tUl+rTqn5vkEHMycz003Y6PoS6rRmnItgXP5eXT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UGlEc9h6aK/gqunBrzVuAGL+tvKxh74yQXnKnDCtIc+AbAH/WsUPykKkK7RKOH7C+ 13jQHxKnokRXTauQOH/5DKMzv2jTfWuj40+/E6TEzqHcKQ8bD/ReCmUptkTxsl+V5J 7WG/N9aNbyAeg0opXpy+mwkEiQ9mE33n+/2Fc1v0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Martin Schwidefsky , Vasily Gorbik Subject: [PATCH 4.9 09/96] s390: add assembler macros for CPU alternatives Date: Thu, 24 May 2018 11:37:52 +0200 Message-Id: <20180524093606.130138989@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin Schwidefsky [ Upstream commit fba9eb7946251d6e420df3bdf7bc45195be7be9a ] Add a header with macros usable in assembler files to emit alternative code sequences. It works analog to the alternatives for inline assmeblies in C files, with the same restrictions and capabilities. The syntax is ALTERNATIVE "", \ "", \ "" and ALTERNATIVE_2 "", \ "", \ "", "", \ "" Reviewed-by: Vasily Gorbik Signed-off-by: Martin Schwidefsky Signed-off-by: Greg Kroah-Hartman --- arch/s390/include/asm/alternative-asm.h | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 arch/s390/include/asm/alternative-asm.h --- /dev/null +++ b/arch/s390/include/asm/alternative-asm.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_S390_ALTERNATIVE_ASM_H +#define _ASM_S390_ALTERNATIVE_ASM_H + +#ifdef __ASSEMBLY__ + +/* + * Check the length of an instruction sequence. The length may not be larger + * than 254 bytes and it has to be divisible by 2. + */ +.macro alt_len_check start,end + .if ( \end - \start ) > 254 + .error "cpu alternatives does not support instructions blocks > 254 bytes\n" + .endif + .if ( \end - \start ) % 2 + .error "cpu alternatives instructions length is odd\n" + .endif +.endm + +/* + * Issue one struct alt_instr descriptor entry (need to put it into + * the section .altinstructions, see below). This entry contains + * enough information for the alternatives patching code to patch an + * instruction. See apply_alternatives(). + */ +.macro alt_entry orig_start, orig_end, alt_start, alt_end, feature + .long \orig_start - . + .long \alt_start - . + .word \feature + .byte \orig_end - \orig_start + .byte \alt_end - \alt_start +.endm + +/* + * Fill up @bytes with nops. The macro emits 6-byte nop instructions + * for the bulk of the area, possibly followed by a 4-byte and/or + * a 2-byte nop if the size of the area is not divisible by 6. + */ +.macro alt_pad_fill bytes + .fill ( \bytes ) / 6, 6, 0xc0040000 + .fill ( \bytes ) % 6 / 4, 4, 0x47000000 + .fill ( \bytes ) % 6 % 4 / 2, 2, 0x0700 +.endm + +/* + * Fill up @bytes with nops. If the number of bytes is larger + * than 6, emit a jg instruction to branch over all nops, then + * fill an area of size (@bytes - 6) with nop instructions. + */ +.macro alt_pad bytes + .if ( \bytes > 0 ) + .if ( \bytes > 6 ) + jg . + \bytes + alt_pad_fill \bytes - 6 + .else + alt_pad_fill \bytes + .endif + .endif +.endm + +/* + * Define an alternative between two instructions. If @feature is + * present, early code in apply_alternatives() replaces @oldinstr with + * @newinstr. ".skip" directive takes care of proper instruction padding + * in case @newinstr is longer than @oldinstr. + */ +.macro ALTERNATIVE oldinstr, newinstr, feature + .pushsection .altinstr_replacement,"ax" +770: \newinstr +771: .popsection +772: \oldinstr +773: alt_len_check 770b, 771b + alt_len_check 772b, 773b + alt_pad ( ( 771b - 770b ) - ( 773b - 772b ) ) +774: .pushsection .altinstructions,"a" + alt_entry 772b, 774b, 770b, 771b, \feature + .popsection +.endm + +/* + * Define an alternative between two instructions. If @feature is + * present, early code in apply_alternatives() replaces @oldinstr with + * @newinstr. ".skip" directive takes care of proper instruction padding + * in case @newinstr is longer than @oldinstr. + */ +.macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2 + .pushsection .altinstr_replacement,"ax" +770: \newinstr1 +771: \newinstr2 +772: .popsection +773: \oldinstr +774: alt_len_check 770b, 771b + alt_len_check 771b, 772b + alt_len_check 773b, 774b + .if ( 771b - 770b > 772b - 771b ) + alt_pad ( ( 771b - 770b ) - ( 774b - 773b ) ) + .else + alt_pad ( ( 772b - 771b ) - ( 774b - 773b ) ) + .endif +775: .pushsection .altinstructions,"a" + alt_entry 773b, 775b, 770b, 771b,\feature1 + alt_entry 773b, 775b, 771b, 772b,\feature2 + .popsection +.endm + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_S390_ALTERNATIVE_ASM_H */