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 B83E6C433FE for ; Wed, 27 Apr 2022 01:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356729AbiD0BeH (ORCPT ); Tue, 26 Apr 2022 21:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347268AbiD0BeF (ORCPT ); Tue, 26 Apr 2022 21:34:05 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00CF02BB35 for ; Tue, 26 Apr 2022 18:30:56 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id u7so294225plg.13 for ; Tue, 26 Apr 2022 18:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=sCWqajasA7ISIMDWcDl8o7kKYsl9k0UXiOkTS2c8CkA=; b=CgjAmV3+4L5oDF5/Ww+PKMhWwfZTnIeyhNvyibGENxZ1fU+LuOuGhRPMqS23/A+UnL 8yD4EvpKtSup8J3Oa3anE+tiHnsreDKDnCmN175zFehTg98rJrfRoQFhcM6VmEidE6Lr TsyHBPX5mG0QFRCUZoXGTn6jtjdtjMJl0+7Mujd7v8wDqRGHKbOH4kgZw9xv2EvoSACx 6VjKo6JFKEAM5nNiyO9Yl9wK1dEGP546Hq0YOv+Zxse9y7VUreXfshGcy6lWuDcFo8mF mCEZWgRGWBPpM3pYSZQ+GQ5DwDJodZA7C+pakJx8z/Dp+ID4qO0gMLy/kpLR9i0xy75E 8IOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sCWqajasA7ISIMDWcDl8o7kKYsl9k0UXiOkTS2c8CkA=; b=S3dn0ssFVgJ9eJsTPHSB3gID3fYn1gPEag7GvFg+WoN56+qbasWNf5bobKlWYmeoIV zrqDwp1GZg2dKOMlA4o9yAn95S76dRxq6k40EeSlRKk4mjn4sO6UVeXDeyI5x2TBI707 HskQOGvTHX7Pn6dYuMfH8qwOLWHkY6MMyiwwyXbriWDK3YQlsVq2kWrlNo1BdE7fKk6D /kXgDzOvxb6t3fKp8XuZmsqyGF3rxLCYbs8UnsujpPNHSP1GgiTz1RzwJYRYh8VAZ+26 Zf1U6MVqe8H2o7K4il2HLbysxCo/yW7HKtJqlAmcC4VPy0053vuW+lITy15+7Hb5AB2B 04Sg== X-Gm-Message-State: AOAM530mMGaKlYSdbVDgEYXmeaZFOONTzpyfrQzZhvYGsYQlnEfI43hR Orq1yjaYRXfRR0KY320nghtLDg== X-Google-Smtp-Source: ABdhPJw1q0Fag74CGwko5HHS4Hk4zlk2TrCAQ78XHacUPoQtem1CluOKqzNTZkS5BQBYQuJ8PiRMqw== X-Received: by 2002:a17:902:e84a:b0:15c:e28c:5f7c with SMTP id t10-20020a170902e84a00b0015ce28c5f7cmr20698565plg.94.1651023056330; Tue, 26 Apr 2022 18:30:56 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id y2-20020a056a00190200b004fa865d1fd3sm17211203pfi.86.2022.04.26.18.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 18:30:56 -0700 (PDT) Date: Wed, 27 Apr 2022 01:30:52 +0000 From: Sean Christopherson To: Mingwei Zhang Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm , LKML , Ben Gardon , David Matlack Subject: Re: [PATCH] KVM: x86/mmu: add lockdep check before lookup_address_in_mm() Message-ID: References: <20220327205803.739336-1-mizhang@google.com> <7597fe2c-ce04-0e21-bd6c-4051d7d5101d@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.