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=-4.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 81E65C433ED for ; Wed, 21 Apr 2021 15:36:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBA9D6143D for ; Wed, 21 Apr 2021 15:36:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBA9D6143D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZEtW-0004qN-Bf for qemu-devel@archiver.kernel.org; Wed, 21 Apr 2021 11:36:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZEr9-0002fH-Tx for qemu-devel@nongnu.org; Wed, 21 Apr 2021 11:33:35 -0400 Received: from mga01.intel.com ([192.55.52.88]:7615) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZEr6-0001ig-SO for qemu-devel@nongnu.org; Wed, 21 Apr 2021 11:33:35 -0400 IronPort-SDR: TVfsNNCa+EOg/3mxPdeqWoZKiS8krC95wzeCelvf0ngDHiX8zPoEOKMwi1KgnpJ74eXBPlPkpk oWweb1Hh0TEQ== X-IronPort-AV: E=McAfee;i="6200,9189,9961"; a="216360180" X-IronPort-AV: E=Sophos;i="5.82,240,1613462400"; d="scan'208";a="216360180" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2021 08:33:20 -0700 IronPort-SDR: UxBFsWCvsd/R6NMhJxHjjMbrqKvsg3VYkgA7KFeTIIF/GG6WwF1SGy7a9udZpN4tpiY3DJJ6yy 06BvKe26m1sg== X-IronPort-AV: E=Sophos;i="5.82,240,1613462400"; d="scan'208";a="427557571" Received: from xiaoyaol-mobl.ccr.corp.intel.com (HELO [10.254.210.165]) ([10.254.210.165]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2021 08:33:17 -0700 Subject: Re: [PATCH v2] i386: Add ratelimit for bus locks acquired in guest To: Eduardo Habkost References: <20210420093736.17613-1-chenyi.qiang@intel.com> <20210420163417.lbns24ypfqz7icxg@habkost.net> <20210421141210.mx5mt7kewahj7eij@habkost.net> <20210421151818.3svsnpmch5gswtpe@habkost.net> From: Xiaoyao Li Message-ID: <07e029d1-2b57-14a8-3860-a621026b604f@intel.com> Date: Wed, 21 Apr 2021 23:33:15 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <20210421151818.3svsnpmch5gswtpe@habkost.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=192.55.52.88; envelope-from=xiaoyao.li@intel.com; helo=mga01.intel.com X-Spam_score_int: -58 X-Spam_score: -5.9 X-Spam_bar: ----- X-Spam_report: (-5.9 / 5.0 requ) BAYES_00=-1.9, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.999, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Richard Henderson , Chenyi Qiang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 4/21/2021 11:18 PM, Eduardo Habkost wrote: > On Wed, Apr 21, 2021 at 10:50:10PM +0800, Xiaoyao Li wrote: >> On 4/21/2021 10:12 PM, Eduardo Habkost wrote: >>> On Wed, Apr 21, 2021 at 02:26:42PM +0800, Chenyi Qiang wrote: >>>> Hi, Eduardo, thanks for your comments! >>>> >>>> >>>> On 4/21/2021 12:34 AM, Eduardo Habkost wrote: >>>>> Hello, >>>>> >>>>> Thanks for the patch. Comments below: >>>>> >>>>> On Tue, Apr 20, 2021 at 05:37:36PM +0800, Chenyi Qiang wrote: >>>>>> Virtual Machines can exploit bus locks to degrade the performance of >>>>>> system. To address this kind of performance DOS attack, bus lock VM exit >>>>>> is introduced in KVM and it will report the bus locks detected in guest, >>>>>> which can help userspace to enforce throttling policies. >>>>>> >>>>> >>>>> Is there anything today that would protect the system from >>>>> similar attacks from userspace with access to /dev/kvm? >>>>> >>>> >>>> I can't fully understand your meaning for "similar attack with access to >>>> /dev/kvm". But there are some similar associated detection features on bare >>>> metal. >>> >>> What I mean is: you say guests can make a performance DoS attack >>> on the host, and your patch mitigates that. >>> >>> What would be the available methods to prevent untrusted >>> userspace running on the host with access to /dev/kvm from making >>> a similar DoS attack on the host? > > Thanks for all the clarifications below. Considering them, > what's the answer to the question above? One choice would be enabling BUS LOCK VM exit by default/unconditionally in KVM. (Our original attempt is to enable it unconditionally, but people want it to be opted in by user) Or we can use split_lock_detect=fatal to prevent all the split lock in guest. For non-wb lock, all the memory should be cacheable as long as no device passthrough to guest. More aggressively, we can enable non-wb lock disable for guest in KVM. >>> >>>> >>>> 1. Split lock detection:https://lore.kernel.org/lkml/158031147976.396.8941798847364718785.tip-bot2@tip-bot2/ >>>> Some CPUs can raise an #AC trap when a split lock is attempted. >>> >>> Would split_lock_detect=fatal be enough to prevent the above attacks? >> >> NO. >> >> There are two types bus lock: >> 1. split lock - lock on cacheable memory while the memory across two cache >> lines. >> 2. non-wb lock - lock on non-writableback memory (you can find it on Intel >> ISE chapter 8, https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html) >> >> split lock detection can only prevent 1) >> >>> Is split_lock_detect=fatal the only available way to prevent them? >> >> as above, 2) non-wb lock can be prevented by "non-wb lock disable" feature > > Bus lock VM exit applies to both 1 and 2, correct? yes! >> >>> >>>> >>>> 2. Bus lock Debug Exception: >>>> https://lore.kernel.org/lkml/20210322135325.682257-1-fenghua.yu@intel.com/ >>>> The kernel can be notified by an #DB trap after a user instruction acquires >>>> a bus lock and is executed. >>> >>> I see a rate limit option mentioned at the above URL. Would a >>> host kernel bus lock rate limit option make this QEMU patch >>> redundant? >>> >> >> No. Bus lock Debug exception cannot be used to detect the bus lock happens >> in guest (vmx non-root mode). >> >> We have patch to virtualize this feature for guest >> https://lore.kernel.org/kvm/20210202090433.13441-1-chenyi.qiang@intel.com/ >> >> that guest will have its own setting of bus lock debug exception on or off. >> >> What's more important is that, even we force set the >> MSR_DEBUGCTL.BUS_LOCK_DETECT for guest, guest still can escape from it. >> Because bus lock #DB is a trap which is delivered after the instruction >> completes. If the instruction acquires bus lock subsequently faults e.g., >> #PF, then no bus lock #DB generated. But the bus lock does happen. >> >> But with bus lock VM exit, even the instruction faults, it will cause a BUS >> LOCK VM exit. >> >> >