From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A92AC4BA24 for ; Thu, 27 Feb 2020 00:11:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 541F724650 for ; Thu, 27 Feb 2020 00:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728105AbgB0ALT (ORCPT ); Wed, 26 Feb 2020 19:11:19 -0500 Received: from mga02.intel.com ([134.134.136.20]:62235 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727987AbgB0ALS (ORCPT ); Wed, 26 Feb 2020 19:11:18 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Feb 2020 16:11:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,490,1574150400"; d="scan'208";a="271951474" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga002.fm.intel.com with ESMTP; 26 Feb 2020 16:11:17 -0800 Date: Wed, 26 Feb 2020 16:11:17 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: Thomas Gleixner , Xiaoyao Li , Ingo Molnar , Borislav Petkov , Andy Lutomirski , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Laight Subject: Re: [PATCH v2 3/6] kvm: x86: Emulate split-lock access as a write Message-ID: <20200227001117.GX9940@linux.intel.com> References: <20200203151608.28053-1-xiaoyao.li@intel.com> <20200203151608.28053-4-xiaoyao.li@intel.com> <95d29a81-62d5-f5b6-0eb6-9d002c0bba23@redhat.com> <878sl945tj.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 11, 2020 at 02:34:18PM +0100, Paolo Bonzini wrote: > On 11/02/20 14:22, Thomas Gleixner wrote: > > Paolo Bonzini writes: > >> On 03/02/20 16:16, Xiaoyao Li wrote: > >>> A sane guest should never tigger emulation on a split-lock access, but > >>> it cannot prevent malicous guest from doing this. So just emulating the > >>> access as a write if it's a split-lock access to avoid malicous guest > >>> polluting the kernel log. > >> > >> Saying that anything doing a split lock access is malicious makes little > >> sense. > > > > Correct, but we also have to accept, that split lock access can be used > > in a malicious way, aka. DoS. > > Indeed, a more accurate emulation such as temporarily disabling > split-lock detection in the emulator would allow the guest to use split > lock access as a vehicle for DoS, but that's not what the commit message > says. If it were only about polluting the kernel log, there's > printk_ratelimited for that. (In fact, if we went for incorrect > emulation as in this patch, a rate-limited pr_warn would be a good idea). > > It is much more convincing to say that since this is pretty much a > theoretical case, we can assume that it is only done with the purpose of > DoS-ing the host or something like that, and therefore we kill the guest. The problem with "kill the guest", and the reason I'd prefer to emulate the split-lock as a write, is that killing the guest in this case is annoyingly difficult. Returning X86EMUL_UNHANDLEABLE / EMULATION_FAILED gets KVM to handle_emulation_failure(), but handle_emulation_failure() will only "kill" the guest if emulation failed in L1 CPL==0. For all other modes, it will inject a #UD and resume the guest. KVM also injects a #UD for L1 CPL==0, but that's the least annoying thing. Adding a new emulation type isn't an option because this code can be triggered through normal emulation. A new return type could be added for split-lock, but that's code I'd really not add, both from an Intel perspective and a KVM maintenance perspective. And, we'd still have the conundrum of what to do if/when split-lock #AC is exposed to L1, e.g. in that case, KVM should inject an #AC into L1, not kill the guest. Again, totally doable, but ugly and IMO an unnecessary maintenance burden. I completely agree that poorly emulating the instruction from the (likely) malicious guest is a hack, but it's a simple and easy to maintain hack. > >> Split lock detection is essentially a debugging feature, there's a > >> reason why the MSR is called "TEST_CTL". So you don't want to make the > > > > The fact that it ended up in MSR_TEST_CTL does not say anything. That's > > where they it ended up to be as it was hastily cobbled together for > > whatever reason. > > Or perhaps it was there all the time in test silicon or something like > that... That would be a very plausible reason for all the quirks behind it. > > Paolo >