From patchwork Wed Nov 2 19:30:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 14467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp106179wru; Wed, 2 Nov 2022 12:48:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ujd5ln9QrYCJe1ENLgFRqNpaL1rIdMS2FhL247glPJvnzm2WIpgNBfXpcX2mNQ/Ocdsn4 X-Received: by 2002:a17:907:3f13:b0:799:6aef:9837 with SMTP id hq19-20020a1709073f1300b007996aef9837mr25711069ejc.296.1667418527729; Wed, 02 Nov 2022 12:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667418527; cv=none; d=google.com; s=arc-20160816; b=crGJR1ouhntUE35cdgnpE+J82Fzurb2O/50uzxNaNwWndLK4/v4xvrylBAOv9Bu8cA fkVTiggcLm3MM7Yi70Lju7r62d8OD4GKfgZYsdLRGLgS/QJ82+/gGmfzd5PSgvdBz1ix ssfboy4XUKxclvw6PX2yYsu+jsChoVD/eu0irpjunvI4iRDxmFgPkZCmhs3ERu9EzQ4W 2Wvbs/ihRDvqQC4yYwKdPls9boDnJR2dxuqQ6qSkn/YPEbfqio6fkw7yy8xmPn8Jc2fS fPoR7N/AJ0OSRM64Bwg40L6v3BlMikao+edtR1mr/4z3K2OaX0Wvds2GFV9xNt2qCmug NHJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=4mfNKilwFmWrqa2spYtO5Tj25NqUdCGG8fx/ELXfW3g=; b=ZoyfkRUQuSilJLqmkWOL86tavs29SXVerOEDexk3k/oTaOpqw02rVIQknu5G+OR5N3 v57BYU0QYRuaMb72sXA4C7MCOt8DY4hVVZCv+LUZe2cqsdNfCVn1eZvlosJG92qJgpFW MGiF9YOCWHwn3bFDI1OJLsUyNT1fbiOvK/WOhssG5dh8I/8AKvurBXXjSrmAcSM1EFwm u/dvdgHi+Jp4jePkPJF7wzz0BNguiCG9kJf7vPSWCEuYdkTICb8VxrPCd7dltr3XItLN AE0sk9bXRfzRKUqpvic46G5HNwz93RQcbrxkfnrSapqr8hF/eLwiy6jcY5+ZOAnqta0z AOjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hhK6C71g; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020a056402358500b004614db9083csi20262913edc.313.2022.11.02.12.48.23; Wed, 02 Nov 2022 12:48:47 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=hhK6C71g; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbiKBTa3 (ORCPT + 99 others); Wed, 2 Nov 2022 15:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiKBTaZ (ORCPT ); Wed, 2 Nov 2022 15:30:25 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B42565CA for ; Wed, 2 Nov 2022 12:30:25 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id v18-20020a637a12000000b0046ed84b94efso9853178pgc.6 for ; Wed, 02 Nov 2022 12:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4mfNKilwFmWrqa2spYtO5Tj25NqUdCGG8fx/ELXfW3g=; b=hhK6C71gMmgCuhyKE25DVYTKUHSUUpT5xEYkm1oWFozn/GMGCDvp3A4t4RmXNVxaaV YWZdMzV2pCTe90Zn/na6/OD8hPoDn73YxV4ek+H8NFrId8pLGs9gB15H/I13eQBbfx03 Zq6aRH94hVD2SytAxjwfY+Ri/baAKSJ3od+LHlYlOX9tmS6OfREqelFSknh3W5pxgFBQ qh6aafaql1y7CMtxFYjFwYw+YXOq7TNxfstUffyK70SfuaA5n68E6m6wAQ3ojftVQnMk EbYETIW/CyYkeJyEUoUKENpYhHAVRBVMKCmzAJZQIkUpXXbjG7IGT+BspHKzZoRUyKbw QGWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4mfNKilwFmWrqa2spYtO5Tj25NqUdCGG8fx/ELXfW3g=; b=FHCTqy5Y423x4/Bs1TpYn4Qvm5VH1day5Ann8VFKVCFIppWXGJIvlGZ+14jynWmhJM wTtIHFo9GjQD372v/J73iL9Sgz+0IqmFz7kfDTOZAf6z1EOTtFyKXSSTukMZhNiTMhEm zXIBjrPHysMrbe+0a5YFH4l0h7Q3Pa/mQw1Czpa0i4zWhn8+r/ElV7mg9mblbXvjvfDk P60rRe1m0xTRLFTFpLWAv7DjzWXVAQ/lVcaum7QOPSmaV7nGtk+lISmsls8eaJRJYj26 fTWSQKE7ui/krXsUGww2A3TtfZJs+3stQQ4igeeaJujxeSHFnC+fwKnTDdrgaq6zsSKt AlJg== X-Gm-Message-State: ACrzQf0cJFwwaBfEegudgG7mhai1DEs+5CXXnZjsATEvfoRdaQJ0J0Jx u0AFMCIEXug14mniuaxpeml1kfEvRB4WhcGjamV2M2U58IQFZ931QshxgzVggq6+vPBS1rI3on+ 53IcimlOE+TmKuumCNFje25egulWR+ypOR4MybkY86r7jMbJfcHwFoEdzI2952aE9xEA6dEqW X-Received: from sweer.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:e45]) (user=bgardon job=sendgmr) by 2002:aa7:9099:0:b0:56a:d3f0:a013 with SMTP id i25-20020aa79099000000b0056ad3f0a013mr26991991pfa.26.1667417424554; Wed, 02 Nov 2022 12:30:24 -0700 (PDT) Date: Wed, 2 Nov 2022 19:30:20 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221102193020.1091939-1-bgardon@google.com> Subject: [PATCH] KVM: x86: Use SRCU to protect zap in __kvm_set_or_clear_apicv_inhibit From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , David Matlack , Anish Ghulati , Ben Gardon X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748415049897664897?= X-GMAIL-MSGID: =?utf-8?q?1748415049897664897?= kvm_zap_gfn_range must be called in an SRCU read-critical section, but there is no SRCU annotation in __kvm_set_or_clear_apicv_inhibit. Add the needed SRCU annotation. Tested: ran tools/testing/selftests/kvm/x86_64/debug_regs on a DBG build. This patch causes the suspicious RCU warning to disappear. Note that the warning is hit in __kvm_zap_rmaps, so kvm_memslots_have_rmaps must return true in order for this to repro (i.e. the TDP MMU must be off or nesting in use.) Fixes: 36222b117e36 ("KVM: x86: don't disable APICv memslot when inhibited") Signed-off-by: Ben Gardon --- arch/x86/kvm/x86.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index cd9eb13e2ed7..6d853e5f683d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10091,7 +10091,10 @@ void __kvm_set_or_clear_apicv_inhibit(struct kvm *kvm, kvm->arch.apicv_inhibit_reasons = new; if (new) { unsigned long gfn = gpa_to_gfn(APIC_DEFAULT_PHYS_BASE); + int idx = srcu_read_lock(&kvm->srcu); + kvm_zap_gfn_range(kvm, gfn, gfn+1); + srcu_read_unlock(&kvm->srcu, idx); } } else { kvm->arch.apicv_inhibit_reasons = new;