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 C3F80C433F5 for ; Wed, 27 Apr 2022 01:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356686AbiD0B1m (ORCPT ); Tue, 26 Apr 2022 21:27:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350789AbiD0B1g (ORCPT ); Tue, 26 Apr 2022 21:27:36 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 602C06E57D for ; Tue, 26 Apr 2022 18:24:26 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id n18so311577plg.5 for ; Tue, 26 Apr 2022 18:24:26 -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=s+1DGNfP27csPmcEuUa6GdLkoCCKVhZfePm8utK72a0=; b=gjJnXOsK4rrfZw+Ws5lrwQU5BDWtyWrRaNnMu7VdbR+x18pJ0FKC8xVKXILOkJdEn9 d68FeNLIwRy2jvUBtHmxu6bckYkT1xpyuBR7kmY0YT944RTmKgN3eT/WNwpkh0dpHP1j Nzu+Zu9su1znHpY4uDer0N3Nr6TFlJmgCg/SeDJ6x5Ag2sklPVV8TbaLzg2dfyf7Yw1a /zYN2skd8pq2/GfYIe7lZyZj3YbB41YaEHlr1J7onqUj+ly9hugUQR0ALOdDpeyWNs5d TGRQ+CfM11cu6lV9tkvwrwXREJr9JpGboX4Qc9Re73LKIl4OUJRxTzqxX7iqquQFKtcL +TPA== 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=s+1DGNfP27csPmcEuUa6GdLkoCCKVhZfePm8utK72a0=; b=pRXY1ZXpHhdZ+DEfphaMdcSjMEsNGXDUov+M4LskZQ1PFNM46b9U/OW/R4O12t+ERx WXAx6ZvxFIIn/3z8pe5j72Y+59lJLzkYscnJ6WpUPZNL4DU2Ompb/5bOv0CAmctANAod 5ziMOidMDhr2A8JzBGzqfFylAsIZVjllROiUfu4RFRzAOQBf/9MtQS+ldDrwOl9vtm7s NKEbyDMBappGsX7oBBG8341MyNB9pfaGjvys6U2XLNTHpsiwMogGWvqQ4ivgnQsXYWhf ff1c9YTsRUFx23IOiexurN95rEEzG04GxXbXUYiVZhsqoeVAvXJAgZF9SC0CNraog9bT GKvw== X-Gm-Message-State: AOAM5315MenHNITGdgEzZxPjU+YS4LGevyjZD3I+eeyy/gGmJaosfwIk TF31viEyPnoY3HlnP98Uu1sqOx3UGHfnVFRcjfvSUg== X-Google-Smtp-Source: ABdhPJwUK91O5b+cbAzQvikG1pLBA2K0awm/orzrnsYaLD/yw4NUbNk63jNIpvhit8xkLMz9irAaJVgaGpEJd3Skf4Q= X-Received: by 2002:a17:903:2444:b0:15d:281d:87 with SMTP id l4-20020a170903244400b0015d281d0087mr9336428pls.9.1651022665690; Tue, 26 Apr 2022 18:24:25 -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 18:24:14 -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: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. ok, I think I can proceed and upload one version for that. Thanks. -Mingwei