From patchwork Wed Oct 4 15:58:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 9985063 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9BE0605A8 for ; Wed, 4 Oct 2017 16:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBD1228B45 for ; Wed, 4 Oct 2017 16:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFFC328B4D; Wed, 4 Oct 2017 16:01:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8BDC628B55 for ; Wed, 4 Oct 2017 16:01:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzm4i-0000KZ-Hi; Wed, 04 Oct 2017 15:59:08 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzm4h-0000Hv-7W for xen-devel@lists.xenproject.org; Wed, 04 Oct 2017 15:59:07 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 38/F9-02044-A4505D95; Wed, 04 Oct 2017 15:59:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpikeJIrShJLcpLzFFi42K52LJdRteT9Wq kwbTJhhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b+9tCCTXwV26ZwNDDe4u5i5OQQEpjNJHFr WzmIzSJgL/Hl91F2EJtRoEziyJr5bF2MHEB2rsSElRJdjFxA5RsZJb6e2M0IUsMmoCVx/O9Jd pAaEQEhiaV360DCzAJHWCVeXNQEsYUFPCUu/vnFAjFeVWLNhQNgrbwCkRKdnz+BreIUMJfY0b eMDeIcM4nt19Yxg9gSAtoSj09PZwTZKyHQxyjRdvUEywRG/gWMDKsY1YtTi8pSi3QN9ZKKMtM zSnITM3N0DQ2M9XJTi4sT01NzEpOK9ZLzczcxAsOGAQh2MC7/6HSIUZKDSUmU99fPK5FCfEn5 KZUZicUZ8UWlOanFhxhlODiUJHjPsVyNFBIsSk1PrUjLzAEGMExagoNHSYT3GUiat7ggMbc4M x0idYpRUUqcdx5IQgAkkVGaB9cGi5pLjLJSwryMQIcI8RSkFuVmlqDKv2IU52BUEubdADKFJz OvBG76K6DFTECL5zRdAVlckoiQkmpgvDHppM/z7mMqMZvW1f6KjVx6RrVMkmvh/N+K+r83fMm pqy5IrFhq/jK43/9Ocf6cW0rz1zw9lX1t9pVjxjc8t7krTE/jevX+9devs9njzAOYVk5Ttsm1 3jDvgF7ti59mwdcsjK+XvIq6o2AgWCO8+IBP+z6nQ1H5jv1PdmpuXpvz0Vns7tMrskosxRmJh lrMRcWJADZUA/qVAgAA X-Env-Sender: jpoimboe@redhat.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1507132744!59822399!1 X-Originating-IP: [209.132.183.28] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA5LjEzMi4xODMuMjggPT4gNTQwNjQ=\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15245 invoked from network); 4 Oct 2017 15:59:05 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by server-4.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 4 Oct 2017 15:59:05 -0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DCD2267D5; Wed, 4 Oct 2017 15:59:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2DCD2267D5 Received: from treble.redhat.com (ovpn-120-76.rdu2.redhat.com [10.10.120.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3066362934; Wed, 4 Oct 2017 15:59:02 +0000 (UTC) From: Josh Poimboeuf To: x86@kernel.org Date: Wed, 4 Oct 2017 10:58:31 -0500 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Oct 2017 15:59:04 +0000 (UTC) Cc: Juergen Gross , Rusty Russell , xen-devel@lists.xenproject.org, Peter Zijlstra , Jiri Slaby , Boris Ostrovsky , Mike Galbraith , linux-kernel@vger.kernel.org, Sasha Levin , Chris Wright , Thomas Gleixner , Andy Lutomirski , "H. Peter Anvin" , Borislav Petkov , live-patching@vger.kernel.org, Alok Kataria , virtualization@lists.linux-foundation.org, Linus Torvalds , Ingo Molnar Subject: [Xen-devel] [PATCH 10/13] x86/alternative: Support indirect call replacement X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add alternative patching support for replacing an instruction with an indirect call. This will be needed for the paravirt alternatives. Signed-off-by: Josh Poimboeuf --- arch/x86/kernel/alternative.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 3344d3382e91..81c577c7deba 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -410,20 +410,28 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start, insnbuf_sz = a->replacementlen; /* - * 0xe8 is a relative jump; fix the offset. - * - * Instruction length is checked before the opcode to avoid - * accessing uninitialized bytes for zero-length replacements. + * Fix the address offsets for call and jump instructions which + * use PC-relative addressing. */ if (a->replacementlen == 5 && *insnbuf == 0xe8) { + /* direct call */ *(s32 *)(insnbuf + 1) += replacement - instr; - DPRINTK("Fix CALL offset: 0x%x, CALL 0x%lx", + DPRINTK("Fix direct CALL offset: 0x%x, CALL 0x%lx", *(s32 *)(insnbuf + 1), (unsigned long)instr + *(s32 *)(insnbuf + 1) + 5); - } - if (a->replacementlen && is_jmp(replacement[0])) + } else if (a->replacementlen == 6 && *insnbuf == 0xff && + *(insnbuf+1) == 0x15) { + /* indirect call */ + *(s32 *)(insnbuf + 2) += replacement - instr; + DPRINTK("Fix indirect CALL offset: 0x%x, CALL *0x%lx", + *(s32 *)(insnbuf + 2), + (unsigned long)instr + *(s32 *)(insnbuf + 2) + 6); + + } else if (a->replacementlen && is_jmp(replacement[0])) { + /* direct jump */ recompute_jump(a, instr, replacement, insnbuf); + } if (a->instrlen > a->replacementlen) { add_nops(insnbuf + a->replacementlen,