Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp375551rwi; Wed, 2 Nov 2022 13:02:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67+wDrx1UGFmbncahehEnw9Q5DM0yYtIXZ7RYTgYvyVRGOC24p5xWi2FIbE97gkF/EUl0V X-Received: by 2002:a17:90a:e2c6:b0:214:184f:4009 with SMTP id fr6-20020a17090ae2c600b00214184f4009mr8656806pjb.220.1667419327735; Wed, 02 Nov 2022 13:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667419327; cv=none; d=google.com; s=arc-20160816; b=ovnLrIBpoO3i7R47C12pKlFYFdWSotUkHuwwCO4GbvVZw6cZbGc8NAgIPn7kyxmqe8 7Yic+G2NqSV3D6xkQgntmiO+JtD2njGaLDqfRryE/Ib+SyA6MB1xsZy3BQjrpbgINw3G isoIfqS5/05xgUlesOaQ0nzL8sja/KITOsU39ONFhOHM+pJAdf7bY084EdKsU5UjcuLE vLxLZesQ8Pj/2Dy65UnZwuYS6gTKXpZJ3AYTZK5kk2i0TuAX8s7K/cQRqLtE7RZGfXlK dz3MNgfg6rB7skPbUbGXDhPL9YhLZzzgq0NIFNW085xN5fjpoAz/LuT/VD4AI3Nxbs0j AhWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XZUg37uJOYfpvjSeVnjDTPG9wFYr/ltSGt4/E37UDaE=; b=kMqci3ktg/OXoYhUuyMlfKBJI2WVrph+mcu/zyscahJNalKxvgdjtVwk7fmGpxbs6z fS+fjNjjiK/PMwdnaTVx8mv8wXyvgwMCfRVc/lMfJsqd2z9/piZDVSC2YmdygiB/D0Rs kGu07BdWzuGQUuOZZ41yN3slVKk9aIcEBZeDAPMk/nkDPWw0QnZU+1fB0PUbBNc3t7pO z1pxnU0j381nsV721+idY9S6Qm3sTvq3noY+QJt+R8u8tMVDxi/S0I5FwARFDg7NgADA Cm2r6cI6Nb+QrGg4y6XNs0v8n4Y4UwmAr53j+ZOD0/bPe9DrYvVLIJ3EhmGVd+Jfj92L cHvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=T6n+ZNy6; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb17-20020a17090b281100b0021305ca5933si3436411pjb.42.2022.11.02.13.01.02; Wed, 02 Nov 2022 13:02:07 -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=T6n+ZNy6; 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 S229709AbiKBTr2 (ORCPT + 98 others); Wed, 2 Nov 2022 15:47:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiKBTr0 (ORCPT ); Wed, 2 Nov 2022 15:47:26 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E93E0EE37 for ; Wed, 2 Nov 2022 12:47:24 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id j12so17580341plj.5 for ; Wed, 02 Nov 2022 12:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=XZUg37uJOYfpvjSeVnjDTPG9wFYr/ltSGt4/E37UDaE=; b=T6n+ZNy6EJsuUFK142/EHb28MY0RHQS0F3csirBX1F4szkFH3Oa1GmcjrbMzMqlehR PvjsJwJm7zQIiFKAQ+k5bRqj3r5MNjpdC5QRkWxNtnvQEVAEPB0xpqh4V/qBgfoZFH/0 X3Dr4HnK3V1IBtSh/4vfOTaOu0DmXUFWj6fWoc4wVthF+lGODGd5TBZPkeQhh2JpHeyp ZJoFYF8I+pq6CfhphcrQl+pAJSgexA1ATjhi8/HGr0ViJe2DXVkDmdTX0/O3PAlo5tHC 1qsWaUE1rHB77yvUEvxqLKB8XZrzBsq5tHtS1s84o8MbSlwJZiAU4a0qutIvlFqV3sub sUAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=XZUg37uJOYfpvjSeVnjDTPG9wFYr/ltSGt4/E37UDaE=; b=dqaNgYbMWXkJ7ajdcUwF4AnhMxrMAWvLE13usOk3FX91Oqsxxq4qfcMTauYSbXomyr uPd9pyND3sJNEj2x8FQM93Zy0lmy7iviWfc7i8jzSm7G5uIqpYLiESGZw+CtRNYuKGWb 7h9e7KuVuHZwq5qoGG+W8P1GbEmNOoZDq6OHYRv+1hGSnbnHsvxyrz5kyqa+HDPHGql6 HalVW6itUJAXJIjam6ddVGf2RJZrxNDw2JYoTT6anrU3CZcfzdMldW/ba3041RyJUOBD WGL8VwVh9y5nYmRQwu4uieCOudJ3JLhMOSAzu+XXN7oOz075KY41j+i3hYltKjRj7gJq i4oA== X-Gm-Message-State: ACrzQf2pYu1Xhfc5BckNN4qLtOKrQd2XHrWygpARwGTAulD+C1UeL6WS VlfyBScPBm5wGXt9LeZsOpTlUg== X-Received: by 2002:a17:902:f686:b0:187:16a0:fd2b with SMTP id l6-20020a170902f68600b0018716a0fd2bmr20793406plg.91.1667418444372; Wed, 02 Nov 2022 12:47:24 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id h18-20020a63df52000000b00434272fe870sm7937729pgj.88.2022.11.02.12.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 12:47:24 -0700 (PDT) Date: Wed, 2 Nov 2022 19:47:20 +0000 From: Sean Christopherson To: Ben Gardon Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , David Matlack , Anish Ghulati Subject: Re: [PATCH] KVM: x86: Use SRCU to protect zap in __kvm_set_or_clear_apicv_inhibit Message-ID: References: <20221102193020.1091939-1-bgardon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221102193020.1091939-1-bgardon@google.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Wed, Nov 02, 2022, Ben Gardon wrote: > kvm_zap_gfn_range must be called in an SRCU read-critical section, but Please add parantheses when referencing functions, i.e. kvm_zap_gfn_range(). > there is no SRCU annotation in __kvm_set_or_clear_apicv_inhibit. __kvm_set_or_clear_apicv_inhibit() > Add the needed SRCU annotation. It's not an annotation, acquiring SRCU is very much functional code. > 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.) Please provide the stack trace or at least a verbal description of what paths can reach __kvm_set_or_clear_apicv_inhibit() without holding SRCU, i.e. explain why this bug isn't being hit left and right. E.g. Unconditionally take KVM's SRCU lock in __kvm_set_or_clear_apicv_inhibit() when zapping virtual APIC SPTEs. SRCU must be held when zapping SPTEs in shadow MMUs to protect the gfn=>memslot translation (the TDP MMU walks all roots and so doesn't dereference memslots). In most cases, the inhibits are updated during KVM_RUN and so SRCU is already held, but other ioctls() can also modify inhibits and don't acquire SRCU, e.g. KVM_SET_GUEST_DEBUG and KVM_SET_LAPIC. Acquire SRCU unconditionally to avoid playing whack-a-mole, as nesting SRCU locks is safe and this is not a hot path. > Fixes: 36222b117e36 ("KVM: x86: don't disable APICv memslot when inhibited") Reported-by? IIRC this originated in a syzkaller report?