Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp324821imn; Thu, 28 Jul 2022 01:35:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4s6XNhbyotuvvzbFv12YmbZ+WW0/3HcahreJYufP5efoHmtYKlbVoHBCW52NMLNwGT43J X-Received: by 2002:a17:907:3d89:b0:72f:18b7:9035 with SMTP id he9-20020a1709073d8900b0072f18b79035mr21272792ejc.13.1658997351305; Thu, 28 Jul 2022 01:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658997351; cv=none; d=google.com; s=arc-20160816; b=p0GS5MnFKmk5s2xNol71Tb3mOclHcDlqlMheU3WFHI7LzK+ycdc6K1g6Xf+xmBs6LS Yelff4T4hmAA3RqZ0GOxsvT8A3MsAMEDB/7z+H9KVgoZCbXiGjMYM3U8LIoIwKYkP/oP 5W0qZJ43ZURVsPpptvOnTKhStknutIx8SX19VJndm4CZZdm81DAw3zGor8Ejh787ZRAz KFi9elpd7bVOQxLxyauSB22v3A2ycvJ7YTdVLOiAzudbKG1JfqciBbeo8V7yvkm+7SYx WYUJF+2oyf3pAy8QAbNOOSA+OA6qoc4xJZXYh6NbypaE2HWld8V1ON0jL4t84rEXMC2X iBSA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=E827PqL8HTvjokH/3FVZPMETqHH7l8GxHs17By22Brw=; b=FtUuwycXLvjNy6yxuw7WCUbCco3pkUfNcY/pXx4IZDMBZWBDl7Y6BtTLmo6XqTAwnq TUjWPNE1qKgiLoc4ulq2LvoZfj3ywyV+2niAkIzmr6eD06Hhe7w3mNalKVWpgnlpfRuX HaK3Q2re1YF7mCLCHx2eDqA1Tsu4Njxs96nZ4d0a5bspbEx/piflJfxdMDyfFtgqun/T XSqsq3Msg+/pDFiG/WjGgxEN5FWf68d7m5tsavdFqRcLYaLrwHDeN4EDQG7iCSSpjoVQ ElMmMbsb7RfU1t4Q+U7suiwgtJSRT5yWjKrla67bTSvAPOCLGVAnCOvEfspbUECVM7iM 4fmw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs30-20020a1709072d1e00b00726e142a88esi254484ejc.983.2022.07.28.01.35.26; Thu, 28 Jul 2022 01:35:51 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231701AbiG1IZS (ORCPT + 99 others); Thu, 28 Jul 2022 04:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234371AbiG1IZQ (ORCPT ); Thu, 28 Jul 2022 04:25:16 -0400 Received: from out0-155.mail.aliyun.com (out0-155.mail.aliyun.com [140.205.0.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 293B1B4AC; Thu, 28 Jul 2022 01:25:09 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047187;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---.OfjlJVP_1658996706; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.OfjlJVP_1658996706) by smtp.aliyun-inc.com; Thu, 28 Jul 2022 16:25:07 +0800 From: "Hou Wenlong" To: kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] KVM: x86: Return emulator error if RDMSR/WRMSR emulation failed Date: Thu, 28 Jul 2022 16:25:04 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY 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 The return value of emulator_{get|set}_mst_with_filter() is confused, since msr access error and emulator error are mixed. Although, KVM_MSR_RET_* doesn't conflict with X86EMUL_IO_NEEDED at present, it is better to convert msr access error to emulator error if error value is needed. Signed-off-by: Hou Wenlong --- arch/x86/kvm/x86.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 5366f884e9a7..8df89b9c212f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7908,11 +7908,12 @@ static int emulator_get_msr_with_filter(struct x86_emulate_ctxt *ctxt, int r; r = kvm_get_msr_with_filter(vcpu, msr_index, pdata); - - if (r && kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_RDMSR, 0, - complete_emulated_rdmsr, r)) { - /* Bounce to user space */ - return X86EMUL_IO_NEEDED; + if (r) { + if (kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_RDMSR, 0, + complete_emulated_rdmsr, r)) + r = X86EMUL_IO_NEEDED; + else + r = X86EMUL_UNHANDLEABLE; } return r; @@ -7925,11 +7926,12 @@ static int emulator_set_msr_with_filter(struct x86_emulate_ctxt *ctxt, int r; r = kvm_set_msr_with_filter(vcpu, msr_index, data); - - if (r && kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_WRMSR, data, - complete_emulated_msr_access, r)) { - /* Bounce to user space */ - return X86EMUL_IO_NEEDED; + if (r > 0) { + if (kvm_msr_user_space(vcpu, msr_index, KVM_EXIT_X86_WRMSR, data, + complete_emulated_msr_access, r)) + r = X86EMUL_IO_NEEDED; + else + r = X86EMUL_UNHANDLEABLE; } return r; -- 2.31.1