From patchwork Fri Aug 2 08:50:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 13751261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D378EC3DA4A for ; Fri, 2 Aug 2024 08:51:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.770745.1181335 (Exim 4.92) (envelope-from ) id 1sZnzz-0002G7-An; Fri, 02 Aug 2024 08:50:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 770745.1181335; Fri, 02 Aug 2024 08:50:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZnzz-0002G0-8L; Fri, 02 Aug 2024 08:50:55 +0000 Received: by outflank-mailman (input) for mailman id 770745; Fri, 02 Aug 2024 08:50:53 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZnzx-0002FB-Pi for xen-devel@lists.xenproject.org; Fri, 02 Aug 2024 08:50:53 +0000 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [2a00:1450:4864:20::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5303527f-50ac-11ef-bc03-fd08da9f4363; Fri, 02 Aug 2024 10:50:53 +0200 (CEST) Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a7aa212c1c9so998299266b.2 for ; Fri, 02 Aug 2024 01:50:53 -0700 (PDT) Received: from p183 ([46.53.254.37]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7dc9bc3c7asm75265566b.14.2024.08.02.01.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 01:50:51 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5303527f-50ac-11ef-bc03-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722588652; x=1723193452; darn=lists.xenproject.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=AYmXBmScurZjis0yN5U9wEBN6bdZcv2HfflbnZA48t8=; b=htia0v2UEJwW4O5UHGMViuHsKTroOrrhAMvRq1GlxnDCmvgqgIjtwoUeudLV0BtLi6 Xewt/RkchXlWu2cs2733UmGJUxPtorOUALbH+2JkwGhIH2AQ+OdKhddiwFK47JAiXXpk 7FfTYvgAPiZC/2xC4EfA6a5iGsqSJd+BZdrAEy6yi3lGEV8obweKvP8uiMdeTh8Klt5u qei+Jpw/pUhYv4PWntzngd0ZGyzTijkDSY3s7PPZDNz5jAab/K3UxyF1QAVqXpjY3sd6 XL9fZXPComI9lP1r5HzDS1Ht2p6/NO2dDpZ430jGx37pJZyKGsCCjOj+1BMbBXRbpCDS 1G0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722588652; x=1723193452; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AYmXBmScurZjis0yN5U9wEBN6bdZcv2HfflbnZA48t8=; b=J37IqX7y5W2/0FyP2lDQ5hEWXlxQLxdUbJ8YmN0ChcdWG/hqRniX5UQvYvC+aAHWvK hl0+PwQJjac7jiSVpoBkHK55k4QFVE1APT/Uzpj0LqmMInfkUX8RtE3p9hy4YeIJB35I QDkIok7lisJW0Qn+ouSzUngH0e8WTvlybdMvK7eRDXbGcJ9HWIDGCHwbHC0kfcDTH9Ww 3IKXI02+yAGa3QLCRNgJMzRWT2kZy2G1fTbHmke4MhHroxtdxUnraWRI3R7h5MEN+TWZ R0H/xn1jXaghNP+jfhwHh6a0BkXErD+a9ghdQmSR/vOPFhyTPIixyt0ZTgovU08EozTq Y6KQ== X-Gm-Message-State: AOJu0YxI15RmnmzYthn+L5QfFX/IqAZIUd0exYyV1jKlkDnEJKsLNaLt FZ2mJvyRZAtt0Guh1RtzhSFEItrGm/iWH/9YeUEzOoW8gsJsnnU= X-Google-Smtp-Source: AGHT+IFvK4orbI6LNsELu/xB64uvyazNJRbDa2ZxQyhuby6J4ozn+wdc3m9XD6dtz9mA9DlnIRxaMQ== X-Received: by 2002:a17:907:94c5:b0:a77:f2c5:84b3 with SMTP id a640c23a62f3a-a7dc4e5a4edmr205120666b.22.1722588652017; Fri, 02 Aug 2024 01:50:52 -0700 (PDT) Date: Fri, 2 Aug 2024 11:50:49 +0300 From: Alexey Dobriyan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Juergen Gross , Boris Ostrovsky Subject: [PATCH 2/3] x86/cpu: fix unbootable VMs by inlining memcmp in hypervisor_cpuid_base Message-ID: <304592cf-e4a7-4ba1-baa6-4941c60f0e3c@p183> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: If this memcmp() is not inlined then PVH early boot code can call into KASAN-instrumented memcmp() which results in unbootable VMs: pvh_start_xen xen_prepare_pvh xen_cpuid_base hypervisor_cpuid_base memcmp Ubuntu's gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) inlines memcmp with patch and the bug is partially fixed. Leave FIXME just in case someone cares enough to compare 3 pairs of integers like 3 pairs of integers. Signed-off-by: Alexey Dobriyan --- arch/x86/include/asm/cpuid.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpuid.h b/arch/x86/include/asm/cpuid.h index 6b122a31da06..3eca7824430e 100644 --- a/arch/x86/include/asm/cpuid.h +++ b/arch/x86/include/asm/cpuid.h @@ -196,7 +196,20 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) for_each_possible_hypervisor_cpuid_base(base) { cpuid(base, &eax, &signature[0], &signature[1], &signature[2]); - if (!memcmp(sig, signature, 12) && + /* + * FIXME rewrite cpuid comparators to accept uint32_t[3]. + * + * This memcmp() + * a) is called from PVH early boot code + * before instrumentation is set up, + * b) may be compiled to "call memcmp" (not inlined), + * c) memcmp() itself may be instrumented. + * + * Any combination of 2 is fine, but all 3 aren't. + * + * Force inline this function call. + */ + if (!__builtin_memcmp(sig, signature, 12) && (leaves == 0 || ((eax - base) >= leaves))) return base; }