Message ID | 20240226143630.33643-73-jiangshanlai@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-81721-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2167609dyb; Mon, 26 Feb 2024 07:59:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVhwAV/3qmHKFrBUnHrzBI65liurhi0Cjk4H/3bO/7JgBVfOe5ypxN2yaJTdEmaDu/HJsAbRJmacMyagzXqrDa3P6GD1w== X-Google-Smtp-Source: AGHT+IF8M8wImkOf+y09To4jOmD30SyIEeGVg2i7vCN/RSl/khXCSeSvxNfFd9vleB66NEe8ce85 X-Received: by 2002:a05:6a00:f8f:b0:6e5:2f97:bff2 with SMTP id ct15-20020a056a000f8f00b006e52f97bff2mr2970890pfb.11.1708963184971; Mon, 26 Feb 2024 07:59:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708963184; cv=pass; d=google.com; s=arc-20160816; b=m/fofV9S6CDAt1xJ2nKMeyJjTR9fK7FG8+aKVIo1hQY8FxvRoY9qvAnvKDydu5gLx9 VKUqqAEqKr7hCDS4QFKw0gRrWmZDgJSQEqlncd7qNOBEr+0FkX3Ux9/ZZKC7CVTvoIx1 kxdtb3Ltf0/8/l7ITRhM21zmao72N2xsqJ7AR6xh1V7Ui9wlycdC7oCMuPjMabJ9ku6k n/lEZInSNYbIJ6iefH6Ww9QF4aEjBKaDXyeG3/7OIz5LZevqRM2uA6IX9wJ0td6A1QYA Npe35pdcvEPOjIbkFv8j38Pfz38efLdroMXyYU57nxLW/j2W95pGkPmODX02YTNqHzzH nvFw== 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=ozpAnnPH2LU7+faQB5EOaaa/mJ5DT/kXmcQ3UpGuV/k=; fh=sVRjCY5jpJIbXf+/R+J870iOBUvUsY0FWtZUG9AcFR0=; b=0JYyQE3NbOj1/GvX0Q9Q9B2yxTk9BQa7Mad2SW0j5acmnES0QlWxDcQPuNJl/fawnz s6FfkDdV5IcrOkYRbDIo8SdnZUDO1sWsQHFzJGlUxxI071CZ6sf0qtvRKRzRSDB4wvnj F/HL/S5PIOV0qFBgR7+ZqNulxcxcaDRJ8/rIkKI6ak+kPIOUK9X/CF19EhbCOvvC3+N5 yLAY2ZQQ/ov0BvHWGYcDUQ9sd42y+GH8PnZWVIRi0OmycNQaDNLGq9WccJ19JIdecl8E L/SjrGgmzbXxfegbaNjQvybbFAfQn/rerLKGhZQkvEN17wThtEXmZw3o0J/0lTh/McHm bWWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HOfXGjYW; 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-81721-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81721-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p22-20020a63e656000000b005dc4da211fdsi3897653pgj.141.2024.02.26.07.59.44 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:59:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81721-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HOfXGjYW; 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-81721-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81721-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id DDBB3B2FB07 for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 15:04:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 368B9153BEB; Mon, 26 Feb 2024 14:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HOfXGjYW" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 D420B12FF65; Mon, 26 Feb 2024 14:39:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708958399; cv=none; b=KZxBri8jwVB/w9hmAobU+3kD2jkM6s+ycl0R3QZC4FJgkzZ9I2qDv3wH3eMmcfey+guXdYY9dE7MDcAxjtO8wKbxeFk84bIzt5FpcRYb+KSNe/m2iKbnO8Iybi4K5I41xJ7sgS1EFC1yh++T+PrxuglmR9wBmMSgbRNKAi1OEJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708958399; c=relaxed/simple; bh=iXEXISMa0LFDWwH0oSNq32/ssO3bNLLFAadmTz0LNz8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bvD6JkBNQiJYrNtEAUqE1OhILjasB96j+e08Qyk4pjlQr1ouDG98pHbk65wKgcPN4KmTQjLiJgIKXzbjysMmNoWzu5PkKGC76qKGGUzqqujQTFWOYByb4JsiJ83jxUfgyLYbH2mta4COuuiAuh4e0xBKsU2fBv1zs48cNSx52II= 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=HOfXGjYW; arc=none smtp.client-ip=209.85.214.173 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-f173.google.com with SMTP id d9443c01a7336-1dbd32cff0bso22045055ad.0; Mon, 26 Feb 2024 06:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708958397; x=1709563197; 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=ozpAnnPH2LU7+faQB5EOaaa/mJ5DT/kXmcQ3UpGuV/k=; b=HOfXGjYWTP6tnBFHUQ73Ws43EeJxrZM8JckujZksQcaGxSPCpGbD4+qbmIFYy60IRI KmHoGfosvlLlVB0FPXastSR2S6V+ufyaJ9AKUKD4H4Y61Q5Fnyez/FEhSOsfAjW0xzsa VmBdwtwVdj2P3gKTVliH3wC8g9MTn3xANfDA2WJ8YTre5EOteItxX1ZUQyVn6c61PyXP 9/60w6bHUrWmhTceE2pb2oV1G0DdQ0pQFhS8Wm/lMdBwFljermGdWB6DepFpc4VndcSN 739AFGHwcshPFIWkceqf9lpoqDg0sLZZ/ZYzRxkpcS67vp29cjIVugfhgeOGpm+stHSQ RxNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708958397; x=1709563197; 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=ozpAnnPH2LU7+faQB5EOaaa/mJ5DT/kXmcQ3UpGuV/k=; b=NcmIwCMSU2BQ5S6t6tzH9/yxkp86AcoEzQ2F4yw87XHX/Z+Jtdg2MHIDdUbncMGBRt H/xQ4QQ6JsNxzcKZm4YXTRdPP7ur5DCwXbnAMJwfatZFraMLfoezjQ6tv+VSnHZJTc3v bH99jfPNhKvuBplJ3y6PsIyBKzbTkw93KyPxmUxxOp3xyE7A7FGwoyXGOAgUaBgtQr1b ol94Sffx8/ip3X3+0EMzgYsTyikb+D/JBpJoVTs8nYHugPn+JdHcgqleU+1v3vtUZgNt VpwXC2J0KlznPBBXcTm1Yl+AOF1xs2erRaLi1kb6qJVzrvfZ5Lqjlh+nU9PaHZKiAEv/ clTA== X-Forwarded-Encrypted: i=1; AJvYcCVQCK2hXqxYk4PXrvrafKlPa62AUBnmFPMaqlhBk+8m7ASPOnNDdJg0zfLC56mIC4TFMk2pIjdUq4XPrGPAQQ7PqQFq X-Gm-Message-State: AOJu0YxLlaSBrXAs7mMlXZLMLZhTg9e6lV6njNdIKVp8w2wxiC3j9Gdo mewRL5icQGokoMqd79rsqlSt9ZScaN+Ahpq88ZtLc0YJYPiKu25hz4FOFUSQ X-Received: by 2002:a17:902:d2c2:b0:1db:e7a4:90a8 with SMTP id n2-20020a170902d2c200b001dbe7a490a8mr7447890plc.10.1708958397036; Mon, 26 Feb 2024 06:39:57 -0800 (PST) Received: from localhost ([47.254.32.37]) by smtp.gmail.com with ESMTPSA id v17-20020a170902d09100b001dc11f90512sm3424456plv.126.2024.02.26.06.39.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2024 06:39:56 -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>, Sami Tolvanen <samitolvanen@google.com>, Fangrui Song <maskray@google.com>, Willy Tarreau <w@1wt.eu>, Thomas Garnier <thgarnie@chromium.org>, Josh Poimboeuf <jpoimboe@kernel.org>, Xin Li <xin3.li@intel.com> Subject: [RFC PATCH 72/73] x86/pvm: Use RDTSCP as default in vdso_read_cpunode() Date: Mon, 26 Feb 2024 22:36:29 +0800 Message-Id: <20240226143630.33643-73-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: 1791977780676654840 X-GMAIL-MSGID: 1791977780676654840 |
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 CPUNODE description of the guest cannot be installed into the host's GDT, as this index is also used for the host to retrieve the current CPU in paranoid entry. As a result, LSL in vdso_read_cpunode() does not work correctly for the PVM guest. To address this issue, use RDTSCP as the default in vdso_read_cpunode(), as it is supported by the hypervisor. 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/include/asm/alternative.h | 14 ++++++++++++++ arch/x86/include/asm/segment.h | 14 ++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index cf4b236b47a3..caebb49c5d61 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -299,6 +299,20 @@ static inline int alternatives_text_reserved(void *start, void *end) asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : output : "i" (0), ## input) +/* + * This is similar to alternative_io. But it has two features and + * respective instructions. + * + * If CPU has feature2, newinstr2 is used. + * Otherwise, if CPU has feature1, newinstr1 is used. + * Otherwise, oldinstr is used. + */ +#define alternative_io_2(oldinstr, newinstr1, ft_flags1, newinstr2, \ + ft_flags2, output, input...) \ + asm_inline volatile (ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, \ + newinstr2, ft_flags2) \ + : output : "i" (0), ## input) + /* Like alternative_io, but for replacing a direct call with another one. */ #define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ asm_inline volatile (ALTERNATIVE("call %P[old]", "call %P[new]", ft_flags) \ diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h index 9d6411c65920..555966922e8f 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -253,11 +253,17 @@ static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node) * hoisting it out of the calling function. * * If RDPID is available, use it. + * + * If it is PVM guest and RDPID is not available, use RDTSCP. */ - alternative_io ("lsl %[seg],%[p]", - ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */ - X86_FEATURE_RDPID, - [p] "=a" (p), [seg] "r" (__CPUNODE_SEG)); + alternative_io_2("lsl %[seg],%[p]", + ".byte 0x0f,0x01,0xf9\n\t" /* RDTSCP %eax:%edx, %ecx */ + "mov %%ecx,%%eax\n\t", + X86_FEATURE_KVM_PVM_GUEST, + ".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */ + X86_FEATURE_RDPID, + [p] "=a" (p), [seg] "r" (__CPUNODE_SEG) + : "cx", "dx"); if (cpu) *cpu = (p & VDSO_CPUNODE_MASK);