Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5232188rwb; Tue, 6 Sep 2022 22:23:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR5vn1+RToSrVConP8QcS4Wv2mSid2CrXHMk+OQhDCQueiLIn3dr6aQam7PVLgAC8DoAPFYU X-Received: by 2002:a17:902:ea01:b0:175:458e:65be with SMTP id s1-20020a170902ea0100b00175458e65bemr2009390plg.25.1662528230708; Tue, 06 Sep 2022 22:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662528230; cv=none; d=google.com; s=arc-20160816; b=gaGIkO0sWjlxE+R2U12X1Wa3orCWOIliOy7O04fKpPuTID/EJ4GW1x/CiycUXKDy52 Jr2NSOqPZ43SqeqAsLcLaTu5jffIzic+LRmsxkbyZQF/nsupO0HHX/T09H0chJmwqDe1 DrWs83o3lbgw0hr9WlxX4ai+srYDnhSE2SxBd/erzo/BpGZhRWbEZEXipI7NLn+NB1vr uLgMhY/zLQuktgDXhKrxH6EJhTtoKyCcuc5anMIv3zVzlRnLTeXCUovIoG0jdOK3TPIO pxpy+u6k+pCeuA2AlOjQexpOexgylJkx8D3pO7csS6PU8PUdOfqgRDLwiL7Dy5X8C2Jf p/6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XvX4d4lHGdhmKH0oBQwXf1eY3JxPJlcnylOzEMhTpjw=; b=mNHZHnodazKkkdaxGRgONe3z715TlV/kitceGaSZgxuk7VEy9jydWpFLpXOqlO9Hqo WJf7UVmivLwsUUZsYtRFOdbShRSG6dGS0lVQpJskGGmCzVtSGZPjN6NHjKEljsO8ESb6 bilDL/BXECaAhwy1B6GBHWu2GlHRLZz+gDXBmwHGWL2CSSDTPrBHbqquIzgQJcCZ7gCT K/HFiQCj/vVZiDkOUVhuG4I2flVn25eXbQhTFKJnrSoLHfHteAJg/BTNGAET/GQhMco5 U/4xHRcQv9UzNak11DMzSu2JdexRJoxvtkvs6IkuK8w4iAtcryAAYfKYkisEwutvZl4s Xkkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HDlMGE1D; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 o32-20020a635a20000000b0042b3b3a63bfsi15251980pgb.467.2022.09.06.22.23.23; Tue, 06 Sep 2022 22:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=HDlMGE1D; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S229503AbiIGFO0 (ORCPT + 99 others); Wed, 7 Sep 2022 01:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbiIGFOZ (ORCPT ); Wed, 7 Sep 2022 01:14:25 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45A71B86 for ; Tue, 6 Sep 2022 22:14:22 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-346cd4c3d7aso25655117b3.8 for ; Tue, 06 Sep 2022 22:14:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=XvX4d4lHGdhmKH0oBQwXf1eY3JxPJlcnylOzEMhTpjw=; b=HDlMGE1Dtzvgl4sx6psOG95eCP5fJubOQx5rXOyJx1TDazhk2aqRufACacOJcEYT0r osZ3Lo1Z8fPPZoaylkaghbAM0BQaZlBz1gP+hMcBo5QZ8uGeCzStYKrifJmkD25k/DiH lr7m3LWSVEvxQsKpef0k4kDU4xiwqz9lTMxviETiwgfIWuISK2zTacUHozdB4J3nXS9e F9TMLHMGlC1abNichKH/KwH+iUF/G7XgcKsT6byuUtzTCS35n5mgoqQHWBIs3qPwr01+ aBahQ5C+5fH4hUaf2XYXq92ziiDceVipoSwAWu2HLa44wmTacL94ihW+OhBWGzAAfqfC QwxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=XvX4d4lHGdhmKH0oBQwXf1eY3JxPJlcnylOzEMhTpjw=; b=VO7g+1rBmLivt1sUuWlfo6HtSUc9Hab5X9FzEGQEs11U6kWqQ7NMFErH4//QOwkCpN vhsH5RcyBllEX3vFfurJ+upiuaYEOdtgUSwTWKHdXAR7MYRTbZPfFODyONmVDwW6xz3L 2fH08ocesoPToIwE5N6yLwRx1UB1dFFAoRkwuCdWnVLVcVJCeBN5H0/iPdzgQh92Bo2f ASLRNZvqdBKsvVxMRgbTqXW4Nkd9xDSF5EX44q+k72gZfdlXuxiUutRBFLvdd1SV4DkA vFqWhiIqYJEBe2iRXVwqoFxJJKJyw7oQNV3HPCZrkmcTLVxBiMKUiKiUt58JLAOIT+af r6Og== X-Gm-Message-State: ACgBeo10NA3qVjpcwsXS5IfiTlMmYusvEAss6o69F2gOPOG6+9LpoDgI gl/UINyVfFHUwipoR70Z1KUhyHNJRs1hn252adj2Sw== X-Received: by 2002:a81:66c5:0:b0:345:3b1c:26 with SMTP id a188-20020a8166c5000000b003453b1c0026mr1857526ywc.156.1662527661285; Tue, 06 Sep 2022 22:14:21 -0700 (PDT) MIME-Version: 1.0 References: <0ecb0a4781be933fcadeb56a85070818ef3566e7.1655761627.git.ashish.kalra@amd.com> <20220906150635.mhfvtl2xgdbzr7a5@amd.com> In-Reply-To: From: Marc Orr Date: Tue, 6 Sep 2022 22:14:10 -0700 Message-ID: Subject: Re: [PATCH Part2 v6 09/49] x86/fault: Add support to handle the RMP fault for user address To: "Kalra, Ashish" Cc: "Roth, Michael" , Jarkko Sakkinen , Borislav Petkov , x86 , LKML , kvm list , "linux-coco@lists.linux.dev" , Linux Memory Management List , Linux Crypto Mailing List , Thomas Gleixner , Ingo Molnar , Joerg Roedel , "Lendacky, Thomas" , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , Tony Luck , Sathyanarayanan Kuppuswamy , Alper Gun , "Dr . David Alan Gilbert" Content-Type: text/plain; charset="UTF-8" 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, T_SCC_BODY_TEXT_LINE,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-crypto@vger.kernel.org > >> >But I believe Jarkko's version calculates the correct mask (below), incorporating all 18 offset bits into the 1G page. > >> >>> hex(262144 -1) > >> >'0x3ffff' > >> > >> We can get this simply by doing (page_per_hpage(level)-1), but as I mentioned above this is not what we need. > > >If we actually want the 4K page, I think we would want to use the 0x3ffff mask as Marc suggested to get to the specific 4K RMP entry, which I don't think the current code is trying to do. But maybe that *should* be what we should be doing. > > Ok, I agree to get to the specific 4K RMP entry. Thanks, Michael, for a thorough and complete reply! I have to admit, there was some nuance I missed in my earlier reply. But after reading through what you wrote, I agree, always going to the 4k-entry to get the "assigned" bit and also leveraging the implementation of snp_lookup_rmpentry() to lookup the size bit in the 2M-aligned entry seems like an elegant way to code this up. Assuming this suggestion becomes the consensus, we might consider a comment in the source code to capture this discussion. Otherwise, I think I'll forget all of this the next time I'm reading this code :-). Something like: /* * The guest-assigned bit is always propagated to the paddr's respective 4k RMP * entry -- regardless of the actual RMP page size. In contrast, the RMP page * size, handled in snp_lookup_rmpentry(), is indicated by the 2M-aligned RMP * entry. */