Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp971702rwb; Thu, 11 Aug 2022 13:17:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR712oS97CnNLkE0yTwSkHzGtyRAf/fca94GasXA7uYHzKsVvS6yJjpbHfn6lL/yhfhJ30YD X-Received: by 2002:a17:907:3f0a:b0:730:994f:8d57 with SMTP id hq10-20020a1709073f0a00b00730994f8d57mr478357ejc.538.1660249028397; Thu, 11 Aug 2022 13:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660249028; cv=none; d=google.com; s=arc-20160816; b=TbSmgiW8CwIinNpiti8m6/7NajaGKxdXON9AJxoc9Ksqt0k2WfxUSB9zsOopWSLdP7 vzCft1fyZLrk6Qr/R2Bo9F/UsADmKPAzlGlzHigRqG/V0+vxyMyECnY1joU79F6d/0Ny BAQttmsB0gkyJrsL3Jfa2XRD8gscXqnrZ24UN2Npym5gRdef0stOmJTsO3PSC9wBJwk8 ws1ho5a97NAaw6Fj1nJyOb/TBlZNCeO9pySss6bB67QmEE4jOCTri3CRYfWvKgK2kmKI 6hjY6b/ODRmBum82kw2a1L56Zcf6q+s45CBqon9JwD/ujQDZdn5Wj8+bA0Q0FF8DMXzr CGEA== 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=6C6h2douXEbKvjlwVlWqwWtONTGKw9Ry5BpXAhkzQm8=; b=cveqW5hHu2mlPRzIrlBT7cIaZNu87n7XraFrqPBhUMAjYgW4m06oD7Y1QnljvXoZKh 3THI5ZyNlWfvfcWk1pV5eiYQF9Oz/3AmLmab46t9Mv+wC/uNeANU7xqFnndLuYqgoQEO TXwBZoeBf6UPlL0HVPUvjvsbXyY1otNYIHvkwuRYUElVodIcURlgDRuhJ7hSUVPxZGsl A4jizCfKhL4Yog0E4XbF0Y3P9KONh9bWVfAnbPRaKqBZyumnLjGoQMQ78O1aw9nXlOyB 5RxgxD4cGDmvA+9mQJUggBvhD0O6MmW2GctWHkRwOhn0zbmiYBhTKM3LziRW8qI1aNPp fqZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2022080501 header.b=OUNkHiXa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o16-20020a170906975000b00732989ac0absi155443ejy.42.2022.08.11.13.16.42; Thu, 11 Aug 2022 13:17:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2022080501 header.b=OUNkHiXa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235990AbiHKT6J (ORCPT + 99 others); Thu, 11 Aug 2022 15:58:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235403AbiHKT6I (ORCPT ); Thu, 11 Aug 2022 15:58:08 -0400 Received: from mail.zytor.com (unknown [IPv6:2607:7c80:54:3::138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04C469A980 for ; Thu, 11 Aug 2022 12:58:07 -0700 (PDT) Received: from [127.0.0.1] ([12.0.243.163]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.17.1) with ESMTPSA id 27BJvgKs569142 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Thu, 11 Aug 2022 12:57:42 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 27BJvgKs569142 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2022080501; t=1660247863; bh=6C6h2douXEbKvjlwVlWqwWtONTGKw9Ry5BpXAhkzQm8=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=OUNkHiXa61r2VDfhFAFdkZ0DWvbb+J10yBqngOpngLgsTO5orDjt/vHXx6q2FN9Uc UA7o3SrWGdSNP/UFxpYqg5Rgp3iYtkBBKSaDjrKOkYeSxOz+y+XKLIKC3r2PC4ODcj qMML3rHfhI8WPy/ORk8Ws5Lpuls/mp8MsZ0G4Nd8898EKeSIOHP6hCb4d4yqKBPDRQ 7iRgXeABLrmjScB5i+6o8BwEqwEsxja3WxEwbTen+xcq7xk7kM9G3yYNh1Wn28UK21 WyOb61z5yiGGagki5YFvHH4qeJVaGJjw1t+bm7LU/hfcjrtuYPNXhumAffbb+w/9kj noCmR6tirYSHQ== Date: Thu, 11 Aug 2022 12:57:34 -0700 From: "H. Peter Anvin" To: Sean Christopherson , Adam Dunlap CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Nathan Chancellor , Nick Desaulniers , Tom Rix , "Kirill A. Shutemov" , Kuppuswamy Sathyanarayanan , Andi Kleen , Ben Dooks , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Jacob Xu , Alper Gun , Marc Orr Subject: Re: [PATCH] x86/asm: Force native_apic_mem_read to use mov User-Agent: K-9 Mail for Android In-Reply-To: References: <20220811180010.3067457-1-acdunlap@google.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RDNS_NONE,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On August 11, 2022 12:27:10 PM PDT, Sean Christopherson wrote: >On Thu, Aug 11, 2022, Adam Dunlap wrote: >> Previously, when compiled with clang, native_apic_mem_read gets inlined >> into __xapic_wait_icr_idle and optimized to a testl instruction=2E When >> run in a VM with SEV-ES enabled, it attempts to emulate this >> instruction, but the emulator does not support it=2E Instead, use inlin= e >> assembly to force native_apic_mem_read to use the mov instruction which >> is supported by the emulator=2E >>=20 >> Signed-off-by: Adam Dunlap >> Reviewed-by: Marc Orr >> Reviewed-by: Jacob Xu >> --- >> arch/x86/include/asm/apic=2Eh | 13 ++++++++++++- >> 1 file changed, 12 insertions(+), 1 deletion(-) >>=20 >> diff --git a/arch/x86/include/asm/apic=2Eh b/arch/x86/include/asm/apic= =2Eh >> index 3415321c8240=2E=2E281db79e76a9 100644 >> --- a/arch/x86/include/asm/apic=2Eh >> +++ b/arch/x86/include/asm/apic=2Eh >> @@ -109,7 +109,18 @@ static inline void native_apic_mem_write(u32 reg, = u32 v) >> =20 >> static inline u32 native_apic_mem_read(u32 reg) >> { >> - return *((volatile u32 *)(APIC_BASE + reg)); >> + volatile u32 *addr =3D (volatile u32 *)(APIC_BASE + reg); >> + u32 out; >> + >> + /* >> + * Functionally, what we want to do is simply return *addr=2E However= , >> + * this accesses an MMIO which may need to be emulated in some cases= =2E >> + * The emulator doesn't necessarily support all instructions, so we >> + * force the read from addr to use a mov instruction=2E >> + */ >> + asm_inline("movl %1, %0" : "=3Dr"(out) : "m"(*addr)); >> + >> + return out; > >Can't this just be: > > return readl((void __iomem *)(APIC_BASE + reg)); The very point of the patch is to force a specific instruction sequence=2E