Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp894749rdb; Wed, 6 Dec 2023 03:07:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+wuAm+AND8s0tXXZHlfAIo+UW6yUfGvpaNsVhecRFsvieUniwBAnCTjbfrn9z6ptCAoCz X-Received: by 2002:a05:6a20:be91:b0:18f:97c:3865 with SMTP id gf17-20020a056a20be9100b0018f097c3865mr647059pzb.63.1701860835782; Wed, 06 Dec 2023 03:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701860835; cv=none; d=google.com; s=arc-20160816; b=D8bLauDs3EMQ4Y1umEG/rcblhjNmM/NyjfEpPLU5OF6yWazpl49LEMAkP8WvkY3dvq 5eZTwVLYjY+ybl6KjFYyh+DCuejKP20OVu3uV/BiMcx8dcY5jIYhldoGcrQmSW2xI81W OJHgiD0+zmnkRNeEgqL/cpJu7nmy+d/5Z1N1gGDXhUt8uBIqyznDmHQsadaKXXfFb/+S /fUpUEQp6auW5nasiVXoAcHNpO51QmVMslaKU9DHKZU5RdyGLiPa1bEt5kkhnHxa8XrJ LyXLsj0ocgoVOU2uomDE7AWlz/xW/mf3iojAgOgBdMuoAYb4Rymjg9nlf3TugbTiAhjt E+Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=avZmmojFb5Au74EZMhQdVYNLK9roiJ15+g0jrwBoiSw=; fh=6HI4XXVoZ9cg5n/20ULEXHkDbvE+YuKQCIl36BepVxw=; b=nJMF9b9N3uyOwL+DzKA9D8/i7ocOWlZ86KpXWIWrRYhqqiXtxGaGVewQQ7MFkgh5YW pAS6DQlFX8TFkCh7lKQhAchdMSYPsWga22spT9hWRWTvIZdw2Rgup97gTYONK2JPLwMc cM1wIIoHQETO+xw2bEpwJFbeD6Z51s2COWXnM7NiFQn5Wjbc6QseelU0URP5Tz427Zd+ d5c22PlK0ZcBR1kork+vH86d3SRMCpFsBNRcVXNcSiIapCZUrgwsos3qBhbVse59zye5 U10b9cjCzsBwzwsEKPabFj2hn6p/NqJ9+Xx7Cvq0LSJnHRIb2S6bV6GUfS2HiORhGrRF +zFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=LwoQz6sZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z22-20020a656656000000b005c62adcc87csi10888187pgv.882.2023.12.06.03.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=alien8 header.b=LwoQz6sZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 8A1DC803D03B; Wed, 6 Dec 2023 03:07:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378025AbjLFLG4 (ORCPT + 99 others); Wed, 6 Dec 2023 06:06:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377967AbjLFLGw (ORCPT ); Wed, 6 Dec 2023 06:06:52 -0500 Received: from mail.alien8.de (mail.alien8.de [IPv6:2a01:4f9:3051:3f93::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE8210C8 for ; Wed, 6 Dec 2023 03:06:56 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id 2205C40E00C9; Wed, 6 Dec 2023 11:06:54 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Authentication-Results: mail.alien8.de (amavisd-new); dkim=pass (4096-bit key) header.d=alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mXNI4ZqTJxqJ; Wed, 6 Dec 2023 11:06:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=alien8; t=1701860811; bh=avZmmojFb5Au74EZMhQdVYNLK9roiJ15+g0jrwBoiSw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LwoQz6sZF7v3TIC5zxH5InKXTcjQDBRcbUN7pQ7ss/ZL0eBpAu4Z4SamjFSYBxS5+ abK0dyyzfMXMUz0kIW9hiNrubH+YAZOC5qBpPgRNRYKg6eMrAMYxcc7xruNOKtcOsQ /kIoJKCmdFotUQ7Hfs8PLkiEjUXTRcfW5cEXJUuvN0WdguT5UbpHqL6UD5Wa0GyeFg TSq9IDg4zT6teOGDv0wyEFNnTezLZhCD4UPwJEhEKDzcdS7Ap0x5wwLIt1yiWHlojv y3Vuvxclum0pkUY7xF1wGgg+G/T72lFY7t7XJG76FFewcDnjfZt21ykcUqwwBkoDhC TRUTglDGVMgmD45uK73fRaZTLnAb3Di6wMTrhRlZi9QevkcurVYom43/SaBqsuXUoL SbBFoKcnptSp5Fw+rMRLsF2irYgD6dBWULMUY2GkyLsZaQ98vICrWiT5530dnQteJ+ FERC9Bm9602cnvaSDPJB/c1sk3Uqmat8qqw62p/5Wfmg52dZet5sQ5AIk8T7xJoISz 9eueOzgWq6fhnJiF6UQKb2d7iQ+JE5l1G7PnuUma09mgObuQYBcMjiDa8t8XEsUX6l V1E42Q4+yF/s8Rw8cynzfEWIrLet72IV1jRKkYR6i0kgkkusuVyPq08f1eAfMphwFn MmTgw9uV0uOV6GYam0iyQhq0= Received: from zn.tnic (pd95304da.dip0.t-ipconnect.de [217.83.4.218]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 09C4440E00A9; Wed, 6 Dec 2023 11:06:42 +0000 (UTC) Date: Wed, 6 Dec 2023 12:06:36 +0100 From: Borislav Petkov To: Juergen Gross Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra Subject: Re: [PATCH v5 3/5] x86/alternative: add indirect call patching Message-ID: <20231206110636.GBZXBVvCWj2IDjVk4c@fat_crate.local> References: <20231129133332.31043-1-jgross@suse.com> <20231129133332.31043-4-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231129133332.31043-4-jgross@suse.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 03:07:12 -0800 (PST) On Wed, Nov 29, 2023 at 02:33:30PM +0100, Juergen Gross wrote: > In order to prepare replacing of paravirt patching with alternative > patching, add the capability to replace an indirect call with a direct > one to alternative patching. > > This is done via a new flag ALT_FLAG_CALL as the target of the call > instruction needs to be evaluated using the value of the location > addressed by the indirect call. For convenience add a macro for a > default call instruction. In case it is being used without the new > flag being set, it will result in a BUG() when being executed. As in > most cases the feature used will be X86_FEATURE_ALWAYS add another > macro ALT_CALL_ALWAYS usable for the flags parameter of the ALTERNATIVE > macros. > > For a complete replacement handle the special cases of calling a nop > function and an indirect call of NULL the same way as paravirt does. > > Signed-off-by: Juergen Gross > Signed-off-by: Peter Zijlstra (Intel) That SOB chain basically says that you're PeterZ and you're sending this patch. :) Are you trying to say that he co-developed it or suggested it or Originally-by? Documentation/process/submitting-patches.rst has it all. Also, what I did ontop of this is below as we must dump the full flags now with the debug output since you're adding more flags than ALT_NOT. Also, the naked magic numbers need explanation. Please include into your next submission. Thx. diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e7e53b9e801b..888205234f15 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -395,6 +395,9 @@ noinstr void BUG_func(void) } EXPORT_SYMBOL_GPL(BUG_func); +#define CALL_RIP_REL_PREFIX 0xff +#define CALL_RIP_REL_MODRM 0x15 + /* * Rewrite the "call BUG_func" replacement to point to the target of the * indirect pv_ops call "call *disp(%ip)". @@ -409,11 +412,14 @@ static int alt_replace_call(u8 *instr, u8 *insn_buff, struct alt_instr *a) BUG(); } - if (a->instrlen != 6 || instr[0] != 0xff || instr[1] != 0x15) { + if (a->instrlen != 6 || + instr[0] != CALL_RIP_REL_PREFIX || + instr[1] != CALL_RIP_REL_MODRM) { pr_err("ALT_FLAG_DIRECT_CALL set for unrecognized indirect call\n"); BUG(); } + /* Skip CALL_RIP_REL_PREFIX and CALL_RIP_REL_MODRM */ disp = *(s32 *)(instr + 2); #ifdef CONFIG_X86_64 /* ff 15 00 00 00 00 call *0x0(%rip) */ @@ -493,12 +499,11 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start, continue; } - DPRINTK(ALT, "feat: %s%d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d)", - (a->flags & ALT_FLAG_NOT) ? "!" : "", + DPRINTK(ALT, "feat: %d32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d) flags: 0x%x", a->cpuid >> 5, a->cpuid & 0x1f, instr, instr, a->instrlen, - replacement, a->replacementlen); + replacement, a->replacementlen, a->flags); memcpy(insn_buff, replacement, a->replacementlen); insn_buff_sz = a->replacementlen; -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette