Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1122389rdb; Fri, 9 Feb 2024 10:54:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXOuyBK6Xk/Za51Hxt9CHIn32ketRg7heohBCm4Y4rorWT5SsmbJM4Co1/senGWASTFbeR X-Received: by 2002:a05:6a00:189d:b0:6db:cf4c:d836 with SMTP id x29-20020a056a00189d00b006dbcf4cd836mr2382617pfh.4.1707504872001; Fri, 09 Feb 2024 10:54:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707504871; cv=pass; d=google.com; s=arc-20160816; b=qoKMzg79Skt7O+ILtlnCSkssUAt/bLwoTrP2o47ARiD8mg2leerHwte1X1/nwvPs2o 7wueWAEmLukObbg/bTNt3llMPhggNroZXUVLyGSaNe3liV0fuOigkpqWCKbmQEmoDzH7 qGfPr7CpzBmUcFWbkpSPKypVLp0zvK3U3kM1alvLIx+dYvxeNzHAQq3vy/w1nHPaZ12p ID1u5ylCPJpwyIPnavVGAZGoQSNniay+dfspYCt2KQFS55RPsJE4piRI81ks1wQkCulK bB/8n9asjHO/hykFBHifiSpRXvM5G/unxkybvBTggRUKw0zNLfSOkJMcuhHhgmvoAGYS B2dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=TxepppgEC3P8V7/7bMlcPF10Hibly4nFjR2zsEK0CGc=; fh=3qawZX2w2YEMqybaztnTXswjiBT/6cN+M+TWn3w+X/k=; b=PpXbIf2xE8w99foFNSRpMvgkJrPNlGlnpnOj/wZxU2sfSZK1TVI/w5OzrTKzD+2ITK U37rjOABcXWOnVRuupBSwIrEoQ8+qD7226ydDtXd9FKjEkxchD3ZtqWYongr18ohZaOs 84LN6aOBoIP3Jp7ozKTG/bLk9xKTyKb2dS0PCaFbKuzHkEQLoMP038pg/IqjqA1xrt5M OVdNrAvmSBiLu50GRTUCsyaAYuJWHqg+GJP0SBO23N2ycwOtZwP/AGwWGAy8g7jqXAjL l1mmz9i8u/qvTnxol5u6mpig94o3La4KZz+9svk5WIP32EuKO5t1PzfcXkJsCBzokCf3 86XA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PPzgQnMg; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-59793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXgIJ3Dx9pGllZMW6aebFpa0dQDDrKiiTdUzY9EudjG4m8gLXyrgWvpTBVPEZ4N5MT+yUKU6quFWxK5YRo8F8MyjtgF/cWAurN4CnOceQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ls53-20020a056a00743500b006db05fad13fsi706350pfb.380.2024.02.09.10.54.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 10:54:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59793-linux.lists.archive=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=@google.com header.s=20230601 header.b=PPzgQnMg; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-59793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 BDEF5B2B864 for ; Fri, 9 Feb 2024 18:22:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2837180BF5; Fri, 9 Feb 2024 18:20:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PPzgQnMg" Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 CF9B969E16 for ; Fri, 9 Feb 2024 18:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707502841; cv=none; b=Ypi+CxeSKyyfX14LLFrrvRblfMLsXZaQPI5zhoCoeSpyiPWhvCpOv2CV8xq5hjdoekFc6rIa+yXmlwjTAkH5qFWBBxWblEWgrPSjID1CSZdn0+z4qBDb29VlR1HepDUEfuTQeCPs9vRW1DpYh/Ec8eK0HGh3PH1wHNiZ2veSWtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707502841; c=relaxed/simple; bh=flaRgTjJ3ECoc4R2pegG/D+sFiX6IzLBk6IwXeTkD6c=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rXD+wQwB+Snb2KrR5srkMapEoW/clPIg3WtCWGCU/va4hg1HWVZ3FzEBRS14qcCzdC9hySw2lLd1eiVPnBSGoYJFi7EQ+Zkl29WdT8AftKJN0cDxeA0u9dGKcmJm+IOlfgIoY6jYqGuRhmiuKHvaDtWlwRpfJ2SqWM0r0uS1EF0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PPzgQnMg; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5c66b093b86so1659587a12.0 for ; Fri, 09 Feb 2024 10:20:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707502839; x=1708107639; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TxepppgEC3P8V7/7bMlcPF10Hibly4nFjR2zsEK0CGc=; b=PPzgQnMgq2289eBLNgAz5T15vAq2Tdr5y3KmK4JsfiHcLoPJ0T+WJWkOVawzhywL0m Q+Psq6CwiNpHOJxMZflxjHAS44U8JbmbKuIPY7E6IUHYxtZKUV4EPIi7jk6AMoBtQOE7 t084EZsu2ioIxY+AL5y8TIhUlCLiGJRG+K6oOw9TU5n8CmG9B5iunoAAw0BhBUFYrX/v jNfPcHJDKghax0fkznVG7MXTtrdckVgCeIyJG0012sCiRUwlA10eI+TH0uhZj/YXXiz5 JbNXykgyeE7Mg/2fQfWvEHFoEXodXHlJ3g3Gs+d37ElumRpnBOiPOBrNQ6ERMmyD1CCF D//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707502839; x=1708107639; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TxepppgEC3P8V7/7bMlcPF10Hibly4nFjR2zsEK0CGc=; b=rZ+e2GFQiCD2QE8VbsWkTKSKkQ+GncGKMyOf4zG7+GRLaKAq1yoU0o8mOe6sSRL+Eo R9l2FDaovEOJEochpTnyDTulxxZ39RTX0OZ8JG+3mcczlciPNWRn7XWzQIvjIxGP9HlW i5ONPTcSIz3B3ZSLELXwC1a3+zrjMCivFHxF+aqU5OOmIle6SXZIdGkyEjLf7hZqTCHV DLG+rgzi5jOxvu8rYwXsBWGXe+SajaquMW91V0mom7XZLflQeipX1Xpa3akT4dW3iwBE 7GcVNsEV7T8AuHAdSrPtNCRCZMf1HSB/lywk3INsq1jlzy08x4O+4ax3NBlxXAfKKDMX vnpQ== X-Gm-Message-State: AOJu0Yx0GPzzvkU4GhjmfBzRQVhRTb9NagSRlPSsY/EHodQTs2rgtKZA oYWNP5Jy/m/09tUevsm1iUfeCf2lv7JxoJedQWbyqtdWsi9A3kPPobbNGH/9e/nvtNwYADdl6Au Q86Z8aaX5wnGnUnpXCmkFE6zSaIS7vzdzqJ3i X-Received: by 2002:a17:90a:f0c3:b0:296:1667:e879 with SMTP id fa3-20020a17090af0c300b002961667e879mr2282435pjb.23.1707502838891; Fri, 09 Feb 2024 10:20:38 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240206223620.1833276-1-acdunlap@google.com> <168b4e3b-8076-4fc3-92bc-fcd9f2b516a8@intel.com> In-Reply-To: From: Adam Dunlap Date: Fri, 9 Feb 2024 10:20:22 -0800 Message-ID: Subject: Re: [PATCH v3] x86/asm: Force native_apic_mem_read to use mov To: Ard Biesheuvel Cc: Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Peter Zijlstra (Intel)" , Arjan van de Ven , Wei Liu , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Jacob Xu , Alper Gun , Kevin Loughlin , Peter Gonda Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 9, 2024 at 7:22=E2=80=AFAM Ard Biesheuvel wro= te: > > On Thu, 8 Feb 2024 at 16:48, Dave Hansen wrote: > > > > On 2/6/24 14:36, Adam Dunlap wrote: > > ... > > > In particular, when compiled with clang and run as a SEV-ES or > > > SEV-SNP guest, the compiler would emit a testl instruction which is > > > not supported by the SEV-ES emulator > > > > What changed? Why is this a bug that we're only noticing now? The lin= e > > of code that's modified here is from 2008. > > > > I assume that it's something new in clang, but it'd be great to know > > that for sure. > > > > Might be the use of LTO in the Google prod[uction]kernel. Adam, can you c= onfirm? It doesn't look like it's LTO. I disabled the LTO options in .config and you can see the problem just in a single object file: With gcc: % gdb -batch -ex 'file arch/x86/kernel/apic/ipi.o' -ex 'disassemble apic_mem_wait_icr_idle' Dump of assembler code for function apic_mem_wait_icr_idle: 0x0000000000000260 <+0>: endbr64 0x0000000000000264 <+4>: jmp 0x268 0x0000000000000266 <+6>: pause 0x0000000000000268 <+8>: mov 0xffffffffff5fc300,%eax 0x000000000000026f <+15>: test $0x10,%ah 0x0000000000000272 <+18>: jne 0x266 0x0000000000000274 <+20>: jmpq 0x279 With clang: % gdb -batch -ex 'file arch/x86/kernel/apic/ipi.o' -ex 'disassemble apic_mem_wait_icr_idle' Dump of assembler code for function apic_mem_wait_icr_idle: 0x0000000000000250 <+0>: endbr64 0x0000000000000254 <+4>: testl $0x1000,0xffffffffff5fc300 0x000000000000025f <+15>: je 0x270 0x0000000000000261 <+17>: pause 0x0000000000000263 <+19>: testl $0x1000,0xffffffffff5fc300 0x000000000000026e <+30>: jne 0x261 0x0000000000000270 <+32>: cs jmpq 0x276 This shows how gcc uses mov to load the apic memory and then testl to test it, while clang combines those instructions. I plugged in the relevant subsection into godbolt [0] and it appears the assembly changed in clang 8 (released 2019). I'm not set up to do full compilations with old clang versions, but this is the most likely change point. > this seems like the kind of thing we'll want in -stable in case folks > are compiling stable kernels with new clangs. That makes sense. Note that there was another patch accepted recently that fixed another clang-with-SEV problem [1], so they should probably be backported to the same stable branches since neither is that useful without the other. [0] https://godbolt.org/z/nq9M9e8ex [1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id= =3D1c811d403afd73f04bde82b83b24c754011bd0e8