From patchwork Sat Jan 7 00:12:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13091896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FE9BC5479D for ; Sat, 7 Jan 2023 00:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236354AbjAGAN1 (ORCPT ); Fri, 6 Jan 2023 19:13:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230270AbjAGANS (ORCPT ); Fri, 6 Jan 2023 19:13:18 -0500 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [IPv6:2a0c:5a00:149::26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ADA460877 for ; Fri, 6 Jan 2023 16:13:16 -0800 (PST) Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1pDwpm-004nJ2-Lv; Sat, 07 Jan 2023 01:13:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From; bh=hg9zooN1O1hQoGZZWTKe6bkOQB4jBDV2d3MgPxz019A=; b=euoh2TwK2ZkTlKLjIql8FScE6X myoW8TNVlQ+qdaKkhkJx+rzD8quZ//qZgFHP1Yk1n9rzFcqQFHThkGVBGB4dO6MmFmdDnZhGgMB+K 5d8h9OAgqwI6UsSXnS1gpzq70ekVyuNOLutNGp9GdBh6FX+HtsQ6RLkrtZwlcPL8fBdi24otcynBW LxoiJdIqQNtY7wJ//3PwMenbuPU8kUN7FAPgaKO0Iod7owBt/wryYvLfHgtASQYWyIYBpHYXcqNwn iioebjzkY88T3MAaCrzpxItr9OIZEjASbbBZmvx/Ko5qw3ge90pzgFPIIXu/hc6x1+ZplCWq00JVS ROp48+CA==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1pDwpm-0002cY-CT; Sat, 07 Jan 2023 01:13:14 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1pDwpi-0002mN-KD; Sat, 07 Jan 2023 01:13:10 +0100 From: Michal Luczaj To: kvm@vger.kernel.org Cc: dwmw2@infradead.org, paul@xen.org, seanjc@google.com, pbonzini@redhat.com, Michal Luczaj Subject: [PATCH v2 1/6] KVM: x86: Optimize kvm->lock and SRCU interaction (KVM_SET_PMU_EVENT_FILTER) Date: Sat, 7 Jan 2023 01:12:51 +0100 Message-Id: <20230107001256.2365304-2-mhal@rbox.co> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230107001256.2365304-1-mhal@rbox.co> References: <20230107001256.2365304-1-mhal@rbox.co> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reduce time spent holding kvm->lock: unlock mutex before calling synchronize_srcu_expedited(). Suggested-by: Paolo Bonzini Suggested-by: Sean Christopherson Signed-off-by: Michal Luczaj --- arch/x86/kvm/pmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index eb594620dd75..18f709d3d8ba 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -633,6 +633,7 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp) mutex_lock(&kvm->lock); filter = rcu_replace_pointer(kvm->arch.pmu_event_filter, filter, mutex_is_locked(&kvm->lock)); + mutex_unlock(&kvm->lock); synchronize_srcu_expedited(&kvm->srcu); BUILD_BUG_ON(sizeof(((struct kvm_pmu *)0)->reprogram_pmi) > @@ -643,8 +644,6 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp) kvm_make_all_cpus_request(kvm, KVM_REQ_PMU); - mutex_unlock(&kvm->lock); - r = 0; cleanup: kfree(filter); From patchwork Sat Jan 7 00:12:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13091899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36845C61DB3 for ; Sat, 7 Jan 2023 00:13:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235581AbjAGANd (ORCPT ); Fri, 6 Jan 2023 19:13:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236522AbjAGANa (ORCPT ); Fri, 6 Jan 2023 19:13:30 -0500 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [IPv6:2a0c:5a00:149::26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AD3959FA0 for ; Fri, 6 Jan 2023 16:13:29 -0800 (PST) Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1pDwpz-004nJo-IE; Sat, 07 Jan 2023 01:13:27 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From; bh=Zr05VKeT1x+qeEuutQZXUGyRBc7jl4NVLxkeYLRX+pI=; b=Zo0OL8euCamta4Dw4bs15sClWg hggsV0P+WAN/BSnLCgqil1dFcj/dmstfPAay0fZ8/M87549x2JTuBrtRVnF7t1CXFfceeCP9cF4K9 Fdd2OAhN5JlGSUPvy7TRgLnixfLqfqLc4fYUtQEzzpr8GZpwfZuWYlD7Fac/tmB4I5zJC1S9edTNb jWK1HcR6vWnWVsjJYpJKP32xRIFnxCSOqOXkMlY2UE77iA6X0dUeHTQ+uAaLeQXuK24fkZNDScX7h 7pRutJP5phUjJyc2d02GBiVJCJPX0LbKz6OOZrQlYiUP1Myc9/zyujadD3CLLOd+PdjpI2hLPzZPK aodTS5ew==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1pDwpk-0002cK-57; Sat, 07 Jan 2023 01:13:12 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1pDwpj-0002mN-0b; Sat, 07 Jan 2023 01:13:11 +0100 From: Michal Luczaj To: kvm@vger.kernel.org Cc: dwmw2@infradead.org, paul@xen.org, seanjc@google.com, pbonzini@redhat.com, Michal Luczaj Subject: [PATCH v2 2/6] KVM: x86: Optimize kvm->lock and SRCU interaction (KVM_X86_SET_MSR_FILTER) Date: Sat, 7 Jan 2023 01:12:52 +0100 Message-Id: <20230107001256.2365304-3-mhal@rbox.co> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230107001256.2365304-1-mhal@rbox.co> References: <20230107001256.2365304-1-mhal@rbox.co> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Reduce time spent holding kvm->lock: unlock mutex before calling synchronize_srcu(). Suggested-by: Paolo Bonzini Suggested-by: Sean Christopherson Signed-off-by: Michal Luczaj --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index da4bbd043a7b..7d398e0da834 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6491,12 +6491,12 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, old_filter = srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1); rcu_assign_pointer(kvm->arch.msr_filter, new_filter); + mutex_unlock(&kvm->lock); synchronize_srcu(&kvm->srcu); kvm_free_msr_filter(old_filter); kvm_make_all_cpus_request(kvm, KVM_REQ_MSR_FILTER_CHANGED); - mutex_unlock(&kvm->lock); return 0; } From patchwork Sat Jan 7 00:12:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13091894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED426C5479D for ; Sat, 7 Jan 2023 00:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233592AbjAGANT (ORCPT ); Fri, 6 Jan 2023 19:13:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229550AbjAGANR (ORCPT ); Fri, 6 Jan 2023 19:13:17 -0500 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [IPv6:2a0c:5a00:149::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E71359FA0 for ; Fri, 6 Jan 2023 16:13:16 -0800 (PST) Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1pDwpl-0047fj-GU; Sat, 07 Jan 2023 01:13:13 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From; bh=xV2/TdpTSiQpTHoXJU8/ntXNFQ5M3TbjS3BqvVEG6hA=; b=kByhev+Go+YYEH2x4ASl+56ktq 1bRD9LyMEDXPRTYCzEmtOXTL5YDRkDZsDFHoShDScIJ9Yfn6sHl7RzF1xzCyozxJGjBV6X1uxDlt7 MLGjTiMfLfeQiF/vWeA0IeWvu431lFq5Owh1+psDH8gFS+EwCeJ0PC8yNgSg/zr8Gq1GCM/fOTwGi oVLNm/oqUQsIlxdNMyahA9BHhogJH1o1Bje7A4ksNVhyNcnHQAccuswWmcl9mmd8eHwKBamaaQ4+m TeV0tlcEihqKKxGPM1owcnDFVoyLA3xOJULPqyeydOOl1wxR6pDf/7SkT9bF3849qMoH/e+QukK/f GTYzw9rQ==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1pDwpk-0003vv-OO; Sat, 07 Jan 2023 01:13:12 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1pDwpj-0002mN-DB; Sat, 07 Jan 2023 01:13:11 +0100 From: Michal Luczaj To: kvm@vger.kernel.org Cc: dwmw2@infradead.org, paul@xen.org, seanjc@google.com, pbonzini@redhat.com, Michal Luczaj Subject: [PATCH v2 3/6] KVM: x86: Simplify msr_filter update Date: Sat, 7 Jan 2023 01:12:53 +0100 Message-Id: <20230107001256.2365304-4-mhal@rbox.co> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230107001256.2365304-1-mhal@rbox.co> References: <20230107001256.2365304-1-mhal@rbox.co> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Replace srcu_dereference()+rcu_assign_pointer() sequence with a single rcu_replace_pointer(). Suggested-by: Sean Christopherson Signed-off-by: Michal Luczaj --- arch/x86/kvm/x86.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7d398e0da834..8abce24ec020 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6486,11 +6486,8 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, } mutex_lock(&kvm->lock); - /* The per-VM filter is protected by kvm->lock... */ - old_filter = srcu_dereference_check(kvm->arch.msr_filter, &kvm->srcu, 1); - - rcu_assign_pointer(kvm->arch.msr_filter, new_filter); + old_filter = rcu_replace_pointer(kvm->arch.msr_filter, new_filter, 1); mutex_unlock(&kvm->lock); synchronize_srcu(&kvm->srcu); From patchwork Sat Jan 7 00:12:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13091900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 389D5C5479D for ; Sat, 7 Jan 2023 00:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236448AbjAGANj (ORCPT ); Fri, 6 Jan 2023 19:13:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236308AbjAGANg (ORCPT ); Fri, 6 Jan 2023 19:13:36 -0500 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [IPv6:2a0c:5a00:149::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C2A360877 for ; Fri, 6 Jan 2023 16:13:35 -0800 (PST) Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1pDwq6-0047go-0M; Sat, 07 Jan 2023 01:13:34 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From; bh=Q3rOjDmxnoWl/ThW2e6qlUIU6e7qTV/IJfCXwgxs1r8=; b=cOlnjKRsYvVLm7jXAwlY0gyxZD IvFog5Hk/7ttpVrd+Hq53E4mzNdPt9kN+04dfHNXG7Gk8qXqrq2TOM4KapO6iAr4XN0+xNzjxkXw5 MtTGJ+GrgqR5R56KktHQWs0gsG62Y3tRk9yPy6fIFPW5StdJhaL3PMnMMzZcTpQM/0Kr/SDbI6X3k Kw6CNxRBFMJ8nyYaf6XujkoUpsmd1s9O7PNvzTvcCjrBEzZvRCq5JT3f3ymncr/zViiL2NPH12BPn PU2/XQDXNiSEyjf/R4pifkiVmXGM9D2ued70z6Er7p/PDZYbfM0UXifESJ4SSp+fIftFNbbyEtF5p xumcbicw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1pDwq5-0003xI-FG; Sat, 07 Jan 2023 01:13:33 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1pDwpj-0002mN-Ph; Sat, 07 Jan 2023 01:13:11 +0100 From: Michal Luczaj To: kvm@vger.kernel.org Cc: dwmw2@infradead.org, paul@xen.org, seanjc@google.com, pbonzini@redhat.com, Michal Luczaj Subject: [PATCH v2 4/6] KVM: x86: Explicitly state lockdep condition of msr_filter update Date: Sat, 7 Jan 2023 01:12:54 +0100 Message-Id: <20230107001256.2365304-5-mhal@rbox.co> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230107001256.2365304-1-mhal@rbox.co> References: <20230107001256.2365304-1-mhal@rbox.co> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Replace `1` with the actual mutex_is_locked() check. Suggested-by: Sean Christopherson Signed-off-by: Michal Luczaj --- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8abce24ec020..a35183dc2314 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6487,7 +6487,8 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, mutex_lock(&kvm->lock); /* The per-VM filter is protected by kvm->lock... */ - old_filter = rcu_replace_pointer(kvm->arch.msr_filter, new_filter, 1); + old_filter = rcu_replace_pointer(kvm->arch.msr_filter, new_filter, + mutex_is_locked(&kvm->lock)); mutex_unlock(&kvm->lock); synchronize_srcu(&kvm->srcu); From patchwork Sat Jan 7 00:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13091898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C707C54EBE for ; Sat, 7 Jan 2023 00:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbjAGANc (ORCPT ); Fri, 6 Jan 2023 19:13:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjAGANV (ORCPT ); Fri, 6 Jan 2023 19:13:21 -0500 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [IPv6:2a0c:5a00:149::26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7594D60877 for ; Fri, 6 Jan 2023 16:13:20 -0800 (PST) Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1pDwpq-004nJU-L8; Sat, 07 Jan 2023 01:13:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From; bh=pABIdWrOy9FmO2XYu+ZJ87/PmCSn0Zw4sSM1VsE7V/w=; b=s+t2B5x0cxFlY/PZTyhUGNofin 2tF0RTYFPKd7+314XeLNCbvW0e+jfM9AcI17pBUz6iqdsKCTFnaW+hifV0yply2VPnlpJJLFDa97Y BBxnfnaZUEo47+9tBAgdlo7FgfZk//mxr5wYRkQ9ECROT3obQeV1CYHuagjYLTSq/GiRV7ZuK7gCi 3Zwof5159hDRfz/2a5L+bLFcvin9vIGkqRvW3aS8EhURYWlCZYWH7w0veaoVjblSMDMuJgDvgW5ex PrQ0pZeHBe3648+pvXx4vuXyu/By3l13G75ik7zB2rPE7S3NzgriBqce+956iamHRO0ppZmvX3G/m V28ju0Vg==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1pDwpl-0002cO-B1; Sat, 07 Jan 2023 01:13:13 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1pDwpk-0002mN-68; Sat, 07 Jan 2023 01:13:12 +0100 From: Michal Luczaj To: kvm@vger.kernel.org Cc: dwmw2@infradead.org, paul@xen.org, seanjc@google.com, pbonzini@redhat.com, Michal Luczaj Subject: [PATCH v2 5/6] KVM: x86: Remove unnecessary initialization in kvm_vm_ioctl_set_msr_filter() Date: Sat, 7 Jan 2023 01:12:55 +0100 Message-Id: <20230107001256.2365304-6-mhal@rbox.co> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230107001256.2365304-1-mhal@rbox.co> References: <20230107001256.2365304-1-mhal@rbox.co> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Do not initialize the value of `r`, as it will be overwritten. Signed-off-by: Michal Luczaj --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a35183dc2314..18d5b82eb46d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6460,7 +6460,7 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, struct kvm_x86_msr_filter *new_filter, *old_filter; bool default_allow; bool empty = true; - int r = 0; + int r; u32 i; if (filter->flags & ~KVM_MSR_FILTER_VALID_MASK) From patchwork Sat Jan 7 00:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Luczaj X-Patchwork-Id: 13091895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F37EC54EBE for ; Sat, 7 Jan 2023 00:13:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235283AbjAGANU (ORCPT ); Fri, 6 Jan 2023 19:13:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjAGANR (ORCPT ); Fri, 6 Jan 2023 19:13:17 -0500 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [IPv6:2a0c:5a00:149::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EA3A60863 for ; Fri, 6 Jan 2023 16:13:16 -0800 (PST) Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1pDwpm-0047fo-4w for kvm@vger.kernel.org; Sat, 07 Jan 2023 01:13:14 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From; bh=hfOySL4v9ZcA9e+DFtF8NhZXTTbBvZWPLHUx9AObm0s=; b=YqX8lIatrkmQb6DHsHn6Nbu+t5 U8xxU207rU2UpU6YecNwPEe/G/DDha5Gge8ytn7EJOrZdEkJCSUpjdW6gNxZ3plEGeUtd8dfF7+0x +rLUdVSTws2gENRIDFVaM15JOutzsBiPf42Fg1n/PCuCkcQS4QS83eggtwu/V6sM8asId82eb/eb3 AFjMZpasJ1c74UcQ9MSlpVNkYE5TV7XLCraQHfjHvQ4qb57TpvfzI6/hH62ZcojHBvs5w+ChiSUA0 kZGbUXJvhlUXQ3HB1z7xczzBl5tKR57Dv2XAe2rPO78T2nS4FJbZbnnSh29PPDuIDjvukZ4RiN9X+ 1Ap2At0Q==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1pDwpl-0002cS-Sh; Sat, 07 Jan 2023 01:13:13 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1pDwpk-0002mN-ME; Sat, 07 Jan 2023 01:13:12 +0100 From: Michal Luczaj To: kvm@vger.kernel.org Cc: dwmw2@infradead.org, paul@xen.org, seanjc@google.com, pbonzini@redhat.com, Michal Luczaj Subject: [PATCH v2 6/6] KVM: x86: Simplify msr_io() Date: Sat, 7 Jan 2023 01:12:56 +0100 Message-Id: <20230107001256.2365304-7-mhal@rbox.co> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230107001256.2365304-1-mhal@rbox.co> References: <20230107001256.2365304-1-mhal@rbox.co> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org __msr_io() never returns a negative value. Remove unnecessary checks. Signed-off-by: Michal Luczaj --- arch/x86/kvm/x86.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 18d5b82eb46d..555cc1073841 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4285,8 +4285,8 @@ static int msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs __user *user_msrs, { struct kvm_msrs msrs; struct kvm_msr_entry *entries; - int r, n; unsigned size; + int r; r = -EFAULT; if (copy_from_user(&msrs, user_msrs, sizeof(msrs))) @@ -4303,17 +4303,11 @@ static int msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs __user *user_msrs, goto out; } - r = n = __msr_io(vcpu, &msrs, entries, do_msr); - if (r < 0) - goto out_free; + r = __msr_io(vcpu, &msrs, entries, do_msr); - r = -EFAULT; if (writeback && copy_to_user(user_msrs->entries, entries, size)) - goto out_free; - - r = n; + r = -EFAULT; -out_free: kfree(entries); out: return r;