Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp873106rwb; Thu, 11 Aug 2022 11:23:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR5rh7nRxQINRa1cYtsI50367q7CMg/bv9D8leIZdMYKB4DpGiCEOjWTSOu/CG7gK6OT/+b6 X-Received: by 2002:a17:907:2e01:b0:730:9ecc:cd28 with SMTP id ig1-20020a1709072e0100b007309ecccd28mr223267ejc.360.1660242201642; Thu, 11 Aug 2022 11:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660242201; cv=none; d=google.com; s=arc-20160816; b=nO/17GuG+JQ+2DjG1BXn0AMuqZNHn9nl51E8HDHqEACler9L3zFcxdDE4PdMI6z66d fKo+G+xlKzkFSVUAA/qB0KJlLbJkuhb6/WRjoOk+UTXEqj8ecHeupEXbqMLqF+Amkcni tKNdhTIHBolxO0bIXxdUZrPhHDMUwvTWNqZ946auKBN6v2zYzQEoPXFns1KkTTQK1ILs rVH3D8etFjZuh7s/3+KElF9xSfhGsGcxCqckoFIYiwQJrLRcio9RTQWLGpmc7GjRY8mo YYLlUihzjZIBfXzZsExZpWSPcechcZvawVJ9Z8WSTY6s35KbPDIXnZnkL5Ejd/hFAAEt /zGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=AHPdF2iNp843/qxwt9o0Z5Yx70qagBEm5XUA1AZJq3s=; b=Ka3P96JfuO0xELod2nseNRsZzEJWJ1oGBpzStos40dnp9zkhti9RnIAjYQYezFQDRD QV09iqMX4j5YzP19Cp/NJJZ8UhWW3T7CCrb0nvaHoQBTgCifbPlKd6g81BUwJvyFtyuP MvUiAUABkK9B9YvG91z1J5QiulFdZ4aIRVCwnviWraP9p8MvvFmUnJ5cHE7iOfwwuQN/ YX067Bk46+Y3F23xW7J2PkN4JQliswRmq27JhbMAoRHYG3w/Zj1+hpT2xsphj11a9kBx iVsTVJyFSRVVehqGcYePZOIcu6AK+Vb4J0xqisOsAE8Un8gJPtmc9OeegO9IfGf3Ql87 p2gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hUouphIL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v29-20020a50d09d000000b004408eb05e0csi175503edd.167.2022.08.11.11.22.55; Thu, 11 Aug 2022 11:23:21 -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=@google.com header.s=20210112 header.b=hUouphIL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235215AbiHKSAv (ORCPT + 99 others); Thu, 11 Aug 2022 14:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235108AbiHKSAs (ORCPT ); Thu, 11 Aug 2022 14:00:48 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EE6D85A8E for ; Thu, 11 Aug 2022 11:00:47 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id r13-20020aa7988d000000b0052ed235197bso7169218pfl.20 for ; Thu, 11 Aug 2022 11:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=AHPdF2iNp843/qxwt9o0Z5Yx70qagBEm5XUA1AZJq3s=; b=hUouphILeY+7ZcreKxlU1ukdbwKI/z0PLnXdxgXRyGG+IFml1nB8pn1mmAe2cXc0XR FMB3hhPzAuGQtoJxfAw5hwOsTQmpXmtOFkydYbAXW7d6pcehx4QDo49aKDsCj5o8A324 /VCxSnrbNVogJeIsO+bCb970/vWvnt5k/acHwbkLauSk5dpHDBgRKIdR2Bkj4PH/QF37 ypfexny7+yt3N7PuLCfp3J9Tmb25wfvkeAm7zojmAueiEHE+y+xz1lf/57Ohd4orIeK5 k+zd6pTc3V3h7Ji5hdleQh8BRWqLkmVw5x17GN10XTcnp6/GW/uMVMsVg/H2DMpjWpZY 3ieg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=AHPdF2iNp843/qxwt9o0Z5Yx70qagBEm5XUA1AZJq3s=; b=wdLvZJKCI/L4Y3fFpTLEbHx0MT1egxzKDU3loZN8x194jLB2DFHSiLj469rz9vakC+ d4ogpX+f4V810RmCkQt+k7i/4LxXTLnOOL3Xga5YbQXsFjlDNHBpTSOUn9peW6HfjgE3 BM6ZMpuGBPLwQlsz3nDwTWuLMmKjqdY0btadqcbJ+RgdPlWCyCJqAhSXZcksHKGvC+Ow BZNHx3fpfwanAYnjEMb8DlB0DXEs/2B/sCyMf17IEx5XNel8X6NoR72IJRxmliuvMHua RGAQl9NNJChaxKjU7+QS33sX2NOuCCCaewU6yRsMUjzgdDnewEGZ2SjIL8GjOxQahSO7 uPug== X-Gm-Message-State: ACgBeo2c7HxdAeotyj69fvVlVOtSSj8upJiVo7qhkyU2Gf5zHL2nrQl4 jjr3z4wvM0YiOItMYZJGmzD3pb6WXx1kvA== X-Received: from acdunlap03.bve.corp.google.com ([2620:15c:29:203:7899:c3d8:a49a:7086]) (user=acdunlap job=sendgmr) by 2002:a17:90b:20e:b0:1f5:26b0:f506 with SMTP id fy14-20020a17090b020e00b001f526b0f506mr187731pjb.65.1660240847029; Thu, 11 Aug 2022 11:00:47 -0700 (PDT) Date: Thu, 11 Aug 2022 11:00:10 -0700 Message-Id: <20220811180010.3067457-1-acdunlap@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog Subject: [PATCH] x86/asm: Force native_apic_mem_read to use mov From: Adam Dunlap To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Nathan Chancellor , Nick Desaulniers , Tom Rix , "Kirill A. Shutemov" , Sean Christopherson , Kuppuswamy Sathyanarayanan , Andi Kleen , Adam Dunlap , Ben Dooks , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Cc: Jacob Xu , Alper Gun , Marc Orr Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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 Previously, when compiled with clang, native_apic_mem_read gets inlined into __xapic_wait_icr_idle and optimized to a testl instruction. When run in a VM with SEV-ES enabled, it attempts to emulate this instruction, but the emulator does not support it. Instead, use inline assembly to force native_apic_mem_read to use the mov instruction which is supported by the emulator. Signed-off-by: Adam Dunlap Reviewed-by: Marc Orr Reviewed-by: Jacob Xu --- arch/x86/include/asm/apic.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h index 3415321c8240..281db79e76a9 100644 --- a/arch/x86/include/asm/apic.h +++ b/arch/x86/include/asm/apic.h @@ -109,7 +109,18 @@ static inline void native_apic_mem_write(u32 reg, u32 v) static inline u32 native_apic_mem_read(u32 reg) { - return *((volatile u32 *)(APIC_BASE + reg)); + volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg); + u32 out; + + /* + * Functionally, what we want to do is simply return *addr. However, + * this accesses an MMIO which may need to be emulated in some cases. + * The emulator doesn't necessarily support all instructions, so we + * force the read from addr to use a mov instruction. + */ + asm_inline("movl %1, %0" : "=r"(out) : "m"(*addr)); + + return out; } extern void native_apic_wait_icr_idle(void); -- 2.37.1.559.g78731f0fdb-goog