Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4129813pxb; Tue, 2 Nov 2021 04:46:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMxMSYXk9MwVzKn73B39UBbvv+9oUZu+JWrgCXq8bczLe52WwSP1xJjFotTKCm5782r37h X-Received: by 2002:a5d:878e:: with SMTP id f14mr26036807ion.111.1635853573203; Tue, 02 Nov 2021 04:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635853573; cv=none; d=google.com; s=arc-20160816; b=nBQ5sjiwPz6V/5RJZWrPx70M4d4/FegV6PpYAFzmyUqBMPC2jQnTkYsReIpiftLuly h7lyBDjJ/dlurz1OjtzWZ4s3E4nQnLwHpXm+jvQ8BEStt1BiuHIOxjHBWqr5oTUimZ8g S2Plm2DATN6i/BbOxMzeEBFvWXI0pq1VdpPfllpmtLC0O7RuAqNiYaQxAnxx+tLLm9nB qQAo0xTbOnrW09RtMZ0fQM074bzJWB9aOPoRMds3KfAape5qY0ERcqyT1X60D02vy4gv 6tq4BQQb7MInBP3Cu/9NyExAE3+uEjypXjTFT+nQY2/a3Kin/Xm8YApVCcafZYQDspfj I5fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature:dkim-filter; bh=zKQeGXfsP+l5tBAkLhe3Tvi3JuMR+eopIE+9EA1wQsM=; b=RPUnc7dAAunWXvhmFErig+xdYKD8vCDIQ97YE5xviu7rGQ6kFp6DKDepgknhbIrz/L IeCdFzC/btCEo9yq/gnzJUoZ8Knmpqwm0RMvQQrxcYXcrftRELplqxnq12orAL2uFtxS mUN7pNA/IgPP1xYoTRtvNUQBntbBRLUaEPdook/8F3ywm1P4H6WGdmk0Z6Amye+cqz4G HL7tT9FtaWxuHKueMlLkJDlOf68ws4cdUgEpZXUD0/3G7rIjj//5zhqtNuHEKIuAJDM8 U7RCU1n+Yrdsap7mjhnGRW2TsGT4xbZTYFCZrt+vKjc/nSz9UHOdKNSL5s2xQdQ7hy54 uStA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2021103101 header.b=t9G1OOot; 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=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w8si3933695ill.177.2021.11.02.04.46.01; Tue, 02 Nov 2021 04:46:13 -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=@zytor.com header.s=2021103101 header.b=t9G1OOot; 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=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbhKBLqv (ORCPT + 99 others); Tue, 2 Nov 2021 07:46:51 -0400 Received: from terminus.zytor.com ([198.137.202.136]:53345 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbhKBLqt (ORCPT ); Tue, 2 Nov 2021 07:46:49 -0400 Received: from [127.0.0.1] (81-227-32-128-no2212.tbcn.telia.com [81.227.32.128]) (authenticated bits=0) by mail.zytor.com (8.16.1/8.15.2) with ESMTPSA id 1A2BN0kw425542 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Tue, 2 Nov 2021 04:23:02 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 1A2BN0kw425542 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2021103101; t=1635852184; bh=zKQeGXfsP+l5tBAkLhe3Tvi3JuMR+eopIE+9EA1wQsM=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=t9G1OOot4B9uuHrdKAMpalUcHST3KZcHpw4b1zNsOTmPFQzEzjgkW4i9MQCCPvQDq Tl7sNQ99i7b+Yy/NXeGs0sWc540J4Mxq0YVt4kBOl0yB5VBz9I+uc5Tp9Q8LPyrjz7 lV2GoRLP6LMDOh9gkMeNYxovtOHZSNE8AnMf+2KVpqsrpxnjGNJVAA08FWqiFu18o1 TXFFpkt9pODi0BDJm/xLoO1e43DDJf0MW14h0337K7fkxXncb4u4r/DhlxuPdHIbsy Yzu8cxfYydoC8lPVacveRu9yAl2L1nwIRqd7Kx23zXXsc0c25w7pOvBxRWLsLERShX ywQ5nXMbngBFw== Date: Tue, 02 Nov 2021 12:22:50 +0100 From: "H. Peter Anvin" To: Borislav Petkov , Lai Jiangshan CC: Lai Jiangshan , linux-kernel@vger.kernel.org, x86@kernel.org, Jan Beulich , Thomas Gleixner , Juergen Gross , xen-devel@lists.xenproject.org, Andy Lutomirski , Ingo Molnar , Dave Hansen , Boris Ostrovsky , Stefano Stabellini Subject: =?US-ASCII?Q?Re=3A_=5BPATCH_V4_04/50=5D_x86/xen=3A_Add_xenp?= =?US-ASCII?Q?v=5Frestore=5Fregs=5Fand=5Freturn=5Fto=5Fusermode=28=29?= User-Agent: K-9 Mail for Android In-Reply-To: References: <20211026141420.17138-1-jiangshanlai@gmail.com> <20211026141420.17138-5-jiangshanlai@gmail.com> Message-ID: <6F6D3FEC-9AF1-40E1-A7C2-394D21C40114@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On November 2, 2021 10:49:44 AM GMT+01:00, Borislav Petkov wrote: >On Tue, Nov 02, 2021 at 05:19:46PM +0800, Lai Jiangshan wrote: >> It will add a 5-byte NOP at the beginning of the native >> swapgs_restore_regs_and_return_to_usermode=2E > >So? > It would be interesting to have an "override function with jmp" alternativ= es macro=2E It doesn't require any changes to the alternatives mechanism pr= oper (but possibly to objtool): it would just insert an alternatives entry = without adding any code including nops to the main path=2E It would of cour= se only be applicable to a jmp, so a syntax like OVERRIDE_JMP feature, targ= et rather than open-coding the instruction would probably be a good idea=2E That would reduce the trade-off to zero=2E >> I avoided adding unneeded code in the native code even if it is NOPs >> and avoided melting xenpv-one into the native one which will reduce >> the code readability=2E > >How does this reduce code readability?! > >diff --git a/arch/x86/entry/entry_64=2ES b/arch/x86/entry/entry_64=2ES >index e38a4cf795d9=2E=2Ebf1de54a1fca 100644 >--- a/arch/x86/entry/entry_64=2ES >+++ b/arch/x86/entry/entry_64=2ES >@@ -567,6 +567,10 @@ __irqentry_text_end: >=20 > SYM_CODE_START_LOCAL(common_interrupt_return) > SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL= ) >+ >+ ALTERNATIVE "", "jmp xenpv_restore_regs_and_return_to_usermode", \ >+ X86_FEATURE_XENPV >+ > #ifdef CONFIG_DEBUG_ENTRY > /* Assert that pt_regs indicates user mode=2E */ > testb $3, CS(%rsp) > >> I will follow your preference since a 5-byte NOP is so negligible in th= e slow >> path with an iret instruction=2E > >Yes, we do already gazillion things on those entry and exit paths=2E > >> Or other option that adds macros to wrap the ALTERNATIVE=2E >> RESTORE_REGS_AND_RETURN_TO_USERMODE and >> COND_RESTORE_REGS_AND_RETURN_TO_USERMODE (test %eax before jmp in nativ= e case) > >No, the main goal is to keep the asm code as readable and as simple as >possible=2E > >If macros or whatever need to be added, there better be a good reason >for them=2E Saving a NOP is not one of them=2E > >Thx=2E > --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E