Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6483985rwl; Thu, 29 Dec 2022 13:52:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXvcMPtsQq8hvGDxf+/pXH+MQF88Q4bfSfnRFHK+FLvN9KSCwSiDwlaVGGzxu6d3F99RbJf4 X-Received: by 2002:a05:6a20:4c09:b0:b2:50c3:bb73 with SMTP id fm9-20020a056a204c0900b000b250c3bb73mr32738434pzb.13.1672350754512; Thu, 29 Dec 2022 13:52:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672350754; cv=none; d=google.com; s=arc-20160816; b=E67ILavHJ+rh9dvumSickgN6C9sP+beVW8Q3v7sfpa837lDA+q1yB4pY60E1lDl1Zv jwCoORmGfaY6g5uspGzhjzd+ZPgaHUTZKeK2YRiN7TQeKP3hCxnthqvhZ7mLw0t6Knh9 AcD+fWyViLJQ90bc25DtAii63yjlocuIzCs3MRi+1t0p2gYwCYJ83ZR74pKVNFwdVGJf I8WnznQmPXXGu1m0Z3Nu4j9WEfqhunHV2XjRO+jSfeDnrRbJNfVS1KA/WwFyS7nMt7tF evdSrJuZ59uYjjfB3o+76Uns7UGdys+P+6DJUazo5NZvbHKKEVqjUq87uud5P0FQdA+/ IHjw== 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=2exndYn8ViQnRuRb/vQYpk0y1+W47ptf9X30oZyzwJQ=; b=dipDoPzyHBlSGlKKG/v7aQi90uar2fVxCbs1R+3qay0893fUrRzohIaq6umwszk6Sr R95CR577cyR41UB5CLEasNKT3riz884cjdgSkkTma/Rq0fH00aAQSf9e4TYxxVu2Qufj tX1QMV6wPUCs9pxeEKvRJylVmGEr6nuwYWpo3MZmiE+Z14gImZXH21T6cxsSF2n8BkjM Axs1/6qtvc1LmvSdhxwVPEwM7SsB0xqsv73VmIzS0gmhw19sNKu8CAgXQn7AXPYAyhGy zdKN0RAlU+2i2OZmgXfzJ5wdJ8J3zxYHa5Q/NAhpDl0V4U+1rrv8qa5HQR28jQCylM7H 59Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NmLVWwMD; 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 d5-20020aa78e45000000b00580cb880d09si16070856pfr.232.2022.12.29.13.52.26; Thu, 29 Dec 2022 13:52:34 -0800 (PST) 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=NmLVWwMD; 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 S234158AbiL2VQA (ORCPT + 61 others); Thu, 29 Dec 2022 16:16:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234101AbiL2VPv (ORCPT ); Thu, 29 Dec 2022 16:15:51 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B679362C4 for ; Thu, 29 Dec 2022 13:15:49 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id k19so5664426pfg.11 for ; Thu, 29 Dec 2022 13:15:49 -0800 (PST) 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=2exndYn8ViQnRuRb/vQYpk0y1+W47ptf9X30oZyzwJQ=; b=NmLVWwMDclIYbgxF/2FNy14GbEYvcXrqSVMhKJ16cM0I+HAjCPp9U2zIb4vxwOVtLS Nb0EQidgaW/HJ4a2t1boQfRr0vRdweoq5TPQhnU9yZA7uFMUHS3N5fm2qyvrhldTjA9J H1fe5LNgB741eKmcEpY65yfRPpY4mm5flK9RHXF1C+PZjaQX4ihKdhOz7Wn6e+2E3spj 4i4X+HvtqLv0g+YVajyZJxIEjkEN8mnNynYqnhQ/5N5evN9w1Z9PQLszWeayWF2YotFn 7gs3q4wAf02OzslqAu8KhgMzgR1M0tQIQUkyAx3UW6HofrBar+XnG+sAWSNg3C35G8fZ j5mQ== 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=2exndYn8ViQnRuRb/vQYpk0y1+W47ptf9X30oZyzwJQ=; b=xymMTDuusYdqxilQFfNjhJW0DyYiQ/qjO6+z+uw/yO5Vx44F8jt/7mlTzQ6gtMInlR nsuvEAHWXFizERgkl7GY5dpD9oLaeSMlzXIOpGNTABaQcQNXwWDi5EZ9kg1vVJ7oqvHs Bxqb8Gs36fRhRAOaQLX+0wO/1Yim8TS48zMtcZ+BOjHxcMh/9uEd+Teg8NEKsYI9hclN y2z4JocNYxO7W1u0HsVl3qRM7vV3KDDF3z8eHUBhgvwiquZF3/ozZpqVrLAgslxGtpau BsfvcQ4cORnlGxyDP54oL4ewRwoxP4vq22mkQxPIHWCj0cJ/K+qw3JoVSv1ns8XCHt7v duUA== X-Gm-Message-State: AFqh2kq8WUxZoKSXfO58c8KT3W6ajujLFiggQuj/GOJVZlKSrII6fzuN VTdDoExNrOA8/hBMxwAWDL5zfw== X-Received: by 2002:a05:6a00:1485:b0:575:b783:b6b3 with SMTP id v5-20020a056a00148500b00575b783b6b3mr42576266pfu.28.1672348549094; Thu, 29 Dec 2022 13:15:49 -0800 (PST) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id h1-20020a056a00000100b0058124f92399sm7517540pfk.219.2022.12.29.13.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 13:15:48 -0800 (PST) Date: Thu, 29 Dec 2022 13:15:44 -0800 From: David Matlack To: Vipin Sharma Cc: Ben Gardon , seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [Patch v3 1/9] KVM: x86/mmu: Repurpose KVM MMU shrinker to purge shadow page caches Message-ID: References: <20221222023457.1764-1-vipinsh@google.com> <20221222023457.1764-2-vipinsh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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=unavailable 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, Dec 28, 2022 at 02:07:49PM -0800, Vipin Sharma wrote: > On Tue, Dec 27, 2022 at 10:37 AM Ben Gardon wrote: > > On Wed, Dec 21, 2022 at 6:35 PM Vipin Sharma wrote: > > > > > > Tested this change by running dirty_log_perf_test while dropping cache > > > via "echo 2 > /proc/sys/vm/drop_caches" at 1 second interval > > > continuously. There were WARN_ON(!mc->nobjs) messages printed in kernel > > > logs from kvm_mmu_memory_cache_alloc(), which is expected. > > > > Oh, that's not a good thing. I don't think we want to be hitting those > > warnings. For one, kernel warnings should not be expected behavior, > > probably for many reasons, but at least because Syzbot will find it. > > In this particular case, we don't want to hit that because in that > > case we'll try to do a GFP_ATOMIC, which can fail, and if it fails, > > we'll BUG: > > > > void *kvm_mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc) > > { > > void *p; > > > > if (WARN_ON(!mc->nobjs)) > > p = mmu_memory_cache_alloc_obj(mc, GFP_ATOMIC | __GFP_ACCOUNT); > > else > > p = mc->objects[--mc->nobjs]; > > BUG_ON(!p); > > return p; > > } > > > > Perhaps the risk of actually panicking is small, but it probably > > indicates that we need better error handling around failed allocations > > from the cache. > > Or, the slightly less elegant approach might be to just hold the cache > > lock around the cache topup and use of pages from the cache, but > > adding better error handling would probably be cleaner. > > I was counting on the fact that shrinker will ideally run only in > extreme cases, i.e. host is running on low memory. So, this WARN_ON > will only be rarely used. I was not aware of Syzbot, it seems like it > will be a concern if it does this kind of testing. In an extreme low-memory situation, forcing vCPUS to do GFP_ATOMIC allocations to handle page faults is risky. Plus it's a waste of time to free that memory since it's just going to get immediately reallocated. > > I thought about keeping a mutex, taking it during topup and releasing > it after the whole operation is done but I stopped it as the duration > of holding mutex will be long and might block the memory shrinker > longer. I am not sure though, if this is a valid concern. Use mutex_trylock() to skip any vCPUs that are currently handling page faults.