From mboxrd@z Thu Jan 1 00:00:00 1970 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 57D8BC433F5 for ; Wed, 27 Apr 2022 02:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357302AbiD0DAH (ORCPT ); Tue, 26 Apr 2022 23:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355220AbiD0DAE (ORCPT ); Tue, 26 Apr 2022 23:00:04 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C9B116D98E for ; Tue, 26 Apr 2022 19:56:51 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id j17so441806pfi.9 for ; Tue, 26 Apr 2022 19:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Yvjyzv+d2RYx84AGU+f8Qgb5Z5AEIzJBRa0zZaQL6P8=; b=jCPnHtoKm8g7mbup94ckl16T0R2qbP3Lzt1JMIL7mLKALfxpCjk691OoBHp90yEkdG uyNAhHWeqGd1M4GjcWCFjSg71B6RFukRLbJNYmGtWDhWXOM8ihs8n1dj4b2LY5U0xrnS o6ZUV+Ig063VrlpUNkybJl8mAyWIN8HnIeLTpYhozWJpDDgd2lfqDovBkGvm/LUSivcL opirRHygw9hYsMirg3JAMIWRikwU5TZ308ZptchlsaLSeYISk1gU4m8YFZTkPHBknQiT gGg8me8PQIzO/+sCEyzNZPeNDF31/s28sZK6b5ee9LLPMs7TNVj8ekdNGGvctvcQD+3W xUjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Yvjyzv+d2RYx84AGU+f8Qgb5Z5AEIzJBRa0zZaQL6P8=; b=5nwIju9Ekq6sn3SmDA33+vj9tR+W3GN89b6YvaGhvGVdrVUn1VS3gdW543ik0Yq/bv OqqvinQummw5zF7PzZupiswV2tzkRLopfsxHfKcNhAcypa/wBvqAMcReTn6WnDvmJeIO INH5gLexMuATH7jL7uPLMFr/qI7y0X5mQsOT49jC59z1tHasLGDMKU49VSVVK0lOP4ml nDW5ueIM/RtHmUaebjx1IbOwE9wQFTgdGorkTtWitfjDnrKWKqiTXnfyX03CWcJkMQqB ec18BmFXEWZ+oC5fec+OHjxwJPoCRgotg3vvcYh0ohYN02aE8yO0OxVL8ijuosfpReYE HJ6A== X-Gm-Message-State: AOAM531yLCNZJD8HX32SVHJZmnA6/xm8MQBRE7S8IYQYE4Tk5MxwQ4b8 Jx9sknOa4o8lFje0pJLh4xT6KquvZj9gVBsIfEjyGg== X-Google-Smtp-Source: ABdhPJxjMQtgaZowpVzhPTfplAUMsciMKvA2x/OchoocOj74xMII/JAAJWINHNcc3E1AjGbVUHyB30xLa/zPu6vL0zk= X-Received: by 2002:a63:6809:0:b0:3aa:93f5:c6f3 with SMTP id d9-20020a636809000000b003aa93f5c6f3mr22309806pgc.342.1651028210725; Tue, 26 Apr 2022 19:56:50 -0700 (PDT) MIME-Version: 1.0 References: <20220327205803.739336-1-mizhang@google.com> <7597fe2c-ce04-0e21-bd6c-4051d7d5101d@redhat.com> In-Reply-To: From: Mingwei Zhang Date: Tue, 26 Apr 2022 19:56:39 -0700 Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: add lockdep check before lookup_address_in_mm() To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm , LKML , Ben Gardon , David Matlack Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 26, 2022 at 6:30 PM Sean Christopherson wrote: > > On Tue, Apr 26, 2022, Mingwei Zhang wrote: > > On Tue, Apr 26, 2022 at 6:16 PM Sean Christopherson wrote: > > > > > > On Tue, Apr 26, 2022, Mingwei Zhang wrote: > > > > > I completely agree that lookup_address() and friends are unnecessarily fragile, > > > > > but I think that attempting to harden them to fix this KVM bug will open a can > > > > > of worms and end up delaying getting KVM fixed. > > > > > > > > So basically, we need to: > > > > - choose perf_get_page_size() instead of using any of the > > > > lookup_address*() in mm. > > > > - add a wrapper layer to adapt: 1) irq disabling/enabling and 2) size > > > > -> level translation. > > > > > > > > Agree? > > > > > > Drat, I didn't see that it returns the page size, not the level. That's a bit > > > unfortunate. It definitely makes me less averse to fixing lookup_address_in_pgd() > > > > > > Hrm. I guess since we know there's at least one broken user, and in theory > > > fixing lookup_address_in_pgd() should do no harm to users that don't need protection, > > > it makes sense to just fix lookup_address_in_pgd() and see if the x86 maintainers > > > push back. > > > > Yeah, fixing lookup_address_in_pgd() should be cleaner(), since the > > page fault usage case does not need irq save/restore. But the other > > one needs it. So, we can easily fix the function with READ_ONCE and > > lockless staff. But wrapping the function with irq save/restore from > > the KVM side. > > I think it makes sense to do the save/restore in lookup_address_in_pgd(). The > Those helpers are exported, so odds are good there are broken users that will > benefit from fixing all paths. no, lookup_address_in_pgd() is probably just broken for KVM. In other call sites, some may already disable IRQ, so doing that again inside lookup_address_in_pgd() will be bad. I am looking at here: https://elixir.bootlin.com/linux/latest/source/arch/arm/kernel/traps.c#L304 so, the save/restore are done in oops_begin() and oops_end(), which is wrapping show_fault_oops() that calls lookup_address_in_pgd(). So, I think we need to ensure the READ_ONCE. hmm, regarding the lockless macros, Paolo is right, for x86 it makes no difference. s390 seems to have a different implementation, but kvm_mmu_max_mapping_level() as well as host_pfn_mapping_level are both functions in x86 mmu. Thanks. -Mingwei