Message ID | 20240226143630.33643-72-jiangshanlai@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-81720-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2133600dyb; Mon, 26 Feb 2024 07:04:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVf/mS/tjf+4NDNDFmBtpU0uSFIGi5lwOP+vIRqyJ7fUxT+cByHJi/h1X1K1IJIqsjp3Uztp/imVLUwl0+qnQeG5kADrA== X-Google-Smtp-Source: AGHT+IFMlx1JY5fX4m3XQoITE1jQxck7ctps2uW1IlsSn3xvaEf7Uc/DKum6lhl5h858MGYLWflh X-Received: by 2002:a05:6402:1845:b0:564:56e0:5643 with SMTP id v5-20020a056402184500b0056456e05643mr4812783edy.27.1708959852878; Mon, 26 Feb 2024 07:04:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708959852; cv=pass; d=google.com; s=arc-20160816; b=xpNYGI286ipyxoIrZsXLrJ2EDQltETuZ26OLm8e8S8ZkuJ61+ADbFm0Zf2wJ4mwURN W0EOR/IAz10jD8u4cGV9mmQsn7iRVMsviz+6qidCdSKTlyIPtA6VyMH0ThmQ655n+KI9 mRrm1pIy3b9MFuhfAJNMrKR2OMUce2FmXyJ83F0N7J0K5O+kXozOHgpFhzZPmgGn6J+Q EYQ82GWWCiYsqN9zAg7S5ZQGsxymOnTzuCWfI2VkdeG/n2pyhi3UdoMf9uNy7Ayt5jcf XxhvvlzdgQpqExbL5XlnaFghYHp7a0lNQk5FUe3q4UtsPoBe3xEX92CueBgaNMDhiLjP yRtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+APYg9JF6Nj9qghtD9fNf7B9/lqpn0PpSUUFoa6b37s=; fh=j/8zQnj3RzyH5Dt/1mHxRriZ3idjuCilrMOmWi3Ue5A=; b=ou5RrQhltoI+cm8obJ96Ji0lIApT3aBN9cjlvaf8P3bt4zrUZwigrcQlJ1n91OFycz rAxjNHp4ZNCLfC7DzkjuA2IIU2KZeUQj+uBZ2HAb/oyQK77aiLPcKrAt2GUoA66FXk/0 ieK2A5/UZt6DnSc/22NcxuOMPeRXdvW9WOGmjB2MmtFl8XhGy1YTc9YliGDDjX/okemA UNmCPQmTUKsB9K+CDT7cN2MC20Mm4zHlpAa76BfBqlRIEOUpdHaf4VO3/nRcgCdL0JI+ kpsZJ8uijQR9P8/gJboNpOF3Mfwnc8VmUo1qMUZGqr7XzubJshad0OHBT0ryGRZvnlwK WiFQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZsMtG2cv; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-81720-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81720-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l19-20020a056402255300b00565af82cd08si1982198edb.165.2024.02.26.07.04.12 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:04:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81720-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZsMtG2cv; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-81720-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81720-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9CC651F2DC50 for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 15:03:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34B0F152E17; Mon, 26 Feb 2024 14:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZsMtG2cv" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1213112FF65; Mon, 26 Feb 2024 14:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708958394; cv=none; b=It7QpyFN28its+hFCi0EtC82jQba0dBfdNMNIclsLJRq/5cZ1SrrYQPqHu7uEsCc3ej5J1rII3FWfY37W4LjfIRUOyDDt62Fa/GG/ANVioxVUzEZAzB9tZzJBN7bYhOY5NRTYEDpvZY8PKLWeHa7zGawpvwK5hheokug07hmoKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708958394; c=relaxed/simple; bh=BruDZbIrLo4Z+hSY5ZDPzvxJsJH0osgJZhLwKVbC7e4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tXiml4QqNQgRxU65Tt95oVUIycuZkcwLGTNQ3Vgj8CO4Aze2PKpadF13YXK2EoZhFC/OcLPErcM5eR+Pl+t2k5D/2IS0rd52DXGjYdq6Meb/rlWD747IWUOUg7xwmsx/Qiou6lsjRLTm2ssOjgAl+dZYl2cGgzQIu2PB+mmLe/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZsMtG2cv; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1dcab44747bso5069485ad.1; Mon, 26 Feb 2024 06:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708958392; x=1709563192; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+APYg9JF6Nj9qghtD9fNf7B9/lqpn0PpSUUFoa6b37s=; b=ZsMtG2cv/P/ms+BaQgznmyeKNlwzUMpbRQAVhggt/I5V50wC/4uRQ5P7aSkEAO6s/F XIxsQlYbAXALsUlLVjpKwTuaY4gVmAjXmFC+smV7zRXCxFPf/eL4xle1LVjB2iYmYn0Q +ff39tv/QYJbaTRCTv17CBY2PC3uF7cyDasf3BzWYChKsNQFHq3hfnYTWwAfkQXszdRb q+nB91lskGq+DAPV9jR7RnR0YvBJxcUyxLVtMC9NAgGFjgkowedY9OHhSkYg/7AEJn34 NELxXKVcJbCdRc0XdMMiyEhkwJRwvhPtzTbo3KVM13snnmSJRDW+9WwVAz/lUKRzZt+K pwYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708958392; x=1709563192; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+APYg9JF6Nj9qghtD9fNf7B9/lqpn0PpSUUFoa6b37s=; b=Su4527EYAfvSnlg9XOUz9m3bsl0TPE5kJmdoeVnna5VEI+N09ClmLhQFayfI3rv++f 2lWExhfDuKC228GCnIZ/mMqQnMtltN8v/dbl+9tddmxNpfVc38y2kGN62XjeNns2CSjL HPUdbwg5kL/wik3Hkw8+FblzgrE3gED83o61YUTItCDfDHyD6xN8Wq9aTpQeCM1BW7Gb T5re2L/ZtlsaCJeg5EnAvCu/R4AyW96E/8p3Ak+aKz6knX+N7nJF4fIXMHZRYeGshpZw cVvjqQ0/ss4Ix9BjWpFKnINB/QTuv+j6imFnlLHK2QEIMP/oHgPZq4jC56jnKQhs6K3P oOSw== X-Forwarded-Encrypted: i=1; AJvYcCUxNWce/wTvVsqIUe1hKSfdWWijlfVCXqp0TbF0/jdMG6y1iJ7vJ7kxNjuxoaIS6GtlUhIpPcCwIu9KA2MGJSGkZq3f X-Gm-Message-State: AOJu0YxtP1OYPTy1D6iN5H/pM051ewkrW8BR41ncwOyOAWLM7cXGVGxh lvQIEOIPOWQDiyhum0MXwUXqcGDoN7wBNAlV25kK2sru8bNsv7exg+Hw5HW1 X-Received: by 2002:a17:903:258d:b0:1dc:63fd:39c1 with SMTP id jb13-20020a170903258d00b001dc63fd39c1mr5445941plb.54.1708958391807; Mon, 26 Feb 2024 06:39:51 -0800 (PST) Received: from localhost ([47.89.225.180]) by smtp.gmail.com with ESMTPSA id i6-20020a170902eb4600b001dc0e5ad5desm4032787pli.114.2024.02.26.06.39.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2024 06:39:51 -0800 (PST) From: Lai Jiangshan <jiangshanlai@gmail.com> To: linux-kernel@vger.kernel.org Cc: Hou Wenlong <houwenlong.hwl@antgroup.com>, Lai Jiangshan <jiangshan.ljs@antgroup.com>, Linus Torvalds <torvalds@linux-foundation.org>, Peter Zijlstra <peterz@infradead.org>, Sean Christopherson <seanjc@google.com>, Thomas Gleixner <tglx@linutronix.de>, Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@redhat.com>, kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>, x86@kernel.org, Kees Cook <keescook@chromium.org>, Juergen Gross <jgross@suse.com>, Dave Hansen <dave.hansen@linux.intel.com>, "H. Peter Anvin" <hpa@zytor.com> Subject: [RFC PATCH 71/73] x86/pvm: Adapt pushf/popf in this_cpu_cmpxchg16b_emu() Date: Mon, 26 Feb 2024 22:36:28 +0800 Message-Id: <20240226143630.33643-72-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240226143630.33643-1-jiangshanlai@gmail.com> References: <20240226143630.33643-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791974286613435360 X-GMAIL-MSGID: 1791974286613435360 |
Series |
[RFC,01/73] KVM: Documentation: Add the specification for PVM
|
|
Commit Message
Lai Jiangshan
Feb. 26, 2024, 2:36 p.m. UTC
From: Hou Wenlong <houwenlong.hwl@antgroup.com> The pushf/popf instructions in this_cpu_cmpxchg16b_emu() are non-privilege instructions, so they cannot be trapped and emulated, which could cause a boot failure. However, since the cmpxchg16b instruction is supported for PVM guest. we can patch this_cpu_cmpxchg16b_emu() and use cmpxchg16b directly. Suggested-by: Lai Jiangshan <jiangshan.ljs@antgroup.com> Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com> --- arch/x86/kernel/pvm.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/arch/x86/kernel/pvm.c b/arch/x86/kernel/pvm.c index 1dc2c0fb7daa..567ea19d569c 100644 --- a/arch/x86/kernel/pvm.c +++ b/arch/x86/kernel/pvm.c @@ -413,6 +413,34 @@ __visible noinstr void pvm_event(struct pt_regs *regs) common_interrupt(regs, vector); } +asm ( + ".pushsection .rodata \n" + ".global pvm_cmpxchg16b_emu_template \n" + "pvm_cmpxchg16b_emu_template: \n" + " cmpxchg16b %gs:(%rsi) \n" + " ret \n" + ".global pvm_cmpxchg16b_emu_tail \n" + "pvm_cmpxchg16b_emu_tail: \n" + ".popsection \n" +); + +extern u8 this_cpu_cmpxchg16b_emu[]; +extern u8 pvm_cmpxchg16b_emu_template[]; +extern u8 pvm_cmpxchg16b_emu_tail[]; + +static void __init pvm_early_patch(void) +{ + /* + * The pushf/popf instructions in this_cpu_cmpxchg16b_emu() are + * non-privilege instructions, so they cannot be trapped and emulated, + * which could cause a boot failure. However, since the cmpxchg16b + * instruction is supported for PVM guest. we can patch + * this_cpu_cmpxchg16b_emu() and use cmpxchg16b directly. + */ + memcpy(this_cpu_cmpxchg16b_emu, pvm_cmpxchg16b_emu_template, + (unsigned int)(pvm_cmpxchg16b_emu_tail - pvm_cmpxchg16b_emu_template)); +} + extern void pvm_early_kernel_event_entry(void); /* @@ -457,6 +485,8 @@ void __init pvm_early_setup(void) wrmsrl(MSR_PVM_EVENT_ENTRY, (unsigned long)(void *)pvm_early_kernel_event_entry - 256); wrmsrl(MSR_PVM_SUPERVISOR_REDZONE, PVM_SUPERVISOR_REDZONE_SIZE); wrmsrl(MSR_PVM_RETS_RIP, (unsigned long)(void *)pvm_rets_rip); + + pvm_early_patch(); } void pvm_setup_event_handling(void)