Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2361424pxa; Mon, 3 Aug 2020 14:23:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWxBdC7si6y1P2pMUJ8DkkE/LljUpqJDiSuccSZSdX2dyz0kdU8Kl9WCRL+wC15u1j4+gS X-Received: by 2002:aa7:c74f:: with SMTP id c15mr18024990eds.331.1596489822271; Mon, 03 Aug 2020 14:23:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596489822; cv=none; d=google.com; s=arc-20160816; b=SmmVf6S8xSdg1a26c49+zW338xPRpfoyh8pRSjts80mc0JgI1LJCWO9mNuQAO0m04I yd6n8nA7Klesv0/BLvvRF2sMMAaNOOTNHyLwkarWLaTB92QKKomM3D1yMDJ20iCqFWgK kwghS3jx0T3DCkNWL/1SykyRbFK+BvlYMDp1sgZzgFYUUomBsZNS3J4GHzAjT5vNXnk6 z/6DUeoZ/9EVGeJxloRHh2NsNYqnC8P7ANb0he2c+G46xzVKINZzFyMnnt5bQYT7byTH NiL6bGibaEOfFCegnisqgVImzdgYU4blnpJW27IrIO3+EncJfSURuuNFuSvROC0jV22o UC6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=hUMMAqxPBjlpCLQClDa2cT2Py/z73wH+8gPdSybs9aU=; b=xtgukqaP61w76jaR1o7qic1xpsrNYLVVEBIg9j88vySDQSv5zp64URiwuqKwaGi1Hc vUPeTTC+D5goOTMoKkHlNGFcygBzBzxQzvRD/OljMudTV4F/JFgxWDetUXC1CKss5vcN gHwlEaPBxRnT7WdE7iUpqOfWQo0nYoA+unzRElVSp2h2YNdPUtLgEASSicoyBDQaHF1s +H3j+3tqaD7433/0Xd4YyPRq6V9gzqcULkadxuoYElf7Jf+FWKZa0srr0Cu2cvksI1q6 SQan77TZi0xfDXyP9dR2Ub1BSKI//EFwxdrN1XQF95II3u8YN911gSHZOR675Nm0ZQZ9 6pkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f27si11369070ejj.255.2020.08.03.14.23.18; Mon, 03 Aug 2020 14:23:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729052AbgHCVXJ (ORCPT + 99 others); Mon, 3 Aug 2020 17:23:09 -0400 Received: from mga07.intel.com ([134.134.136.100]:14126 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728256AbgHCVXJ (ORCPT ); Mon, 3 Aug 2020 17:23:09 -0400 IronPort-SDR: NBMuFDmnPKx9NebyCT+vQyF5+jpekkC5oorRcrhjy4WI8uajBFLI6tpIj451/8laR59VHQNI9P 86XAiX78JHYw== X-IronPort-AV: E=McAfee;i="6000,8403,9702"; a="216609915" X-IronPort-AV: E=Sophos;i="5.75,431,1589266800"; d="scan'208";a="216609915" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2020 14:23:08 -0700 IronPort-SDR: hF6njcnE8SnJWNhsZBBlJ4cLXyJa3HDZs8WmMD5zJaubot2BsbrAgt77Fr3PwYgtXgDRFZKxf/ VGAEpUe+uj2w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,431,1589266800"; d="scan'208";a="288237306" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by orsmga003.jf.intel.com with ESMTP; 03 Aug 2020 14:23:08 -0700 Date: Mon, 3 Aug 2020 14:23:08 -0700 From: Sean Christopherson To: Alexander Graf Cc: Vitaly Kuznetsov , Paolo Bonzini , Jonathan Corbet , Wanpeng Li , Jim Mattson , Joerg Roedel , KarimAllah Raslan , Aaron Lewis , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/3] KVM: x86: Introduce allow list for MSR emulation Message-ID: <20200803212307.GI3151@linux.intel.com> References: <20200731214947.16885-1-graf@amazon.com> <20200731214947.16885-3-graf@amazon.com> <87zh7cot7t.fsf@vitty.brq.redhat.com> <2585c6d6-81b0-8375-78ed-862da226ad6c@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2585c6d6-81b0-8375-78ed-862da226ad6c@amazon.com> 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 Mon, Aug 03, 2020 at 10:50:53PM +0200, Alexander Graf wrote: > > On 03.08.20 13:37, Vitaly Kuznetsov wrote: > >>+static int kvm_vm_ioctl_clear_msr_allowlist(struct kvm *kvm) > >>+{ > >>+ mutex_lock(&kvm->lock); > >>+ kvm->arch.msr_allowlist_ranges_count = 0; > >>+ mutex_unlock(&kvm->lock); > > > >Are we also supposed to kfree() bitmaps here? > > Phew. Yes, because without the kfree() we're leaking memory. Unfortunately > if I just put in a kfree() here, we may allow a concurrently executing vCPU > to access already free'd memory. > > So I'll also add locking around the range check. Let's hope it won't regress > performance too much. What about using KVM's SRCU to protect the list? The only thing I'm not 100% on is whether holding kvm->lock across synchronize_srcu() is safe from a lock inversion perspective. I'm pretty sure KVM doesn't try to acquire kvm->lock after grabbing SRCU, but that's hard to audit and there aren't any existing flows that invoke synchronize_srcu() while holding kvm->lock.