Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4465992rwb; Tue, 6 Sep 2022 07:57:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR6igPRPu0drwELySbOtvi5BB6VkWlqAZ6hv6BSjBrYFAz1UfOoHeOzZVNhNRSfx2h/69avW X-Received: by 2002:a17:906:dac8:b0:741:545b:796a with SMTP id xi8-20020a170906dac800b00741545b796amr31448606ejb.240.1662476267810; Tue, 06 Sep 2022 07:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476267; cv=none; d=google.com; s=arc-20160816; b=e9JIDTyKNOA4Ayjb/OYtHJ3kfQdI+Gvw2IW2E7OYo9qVj152c3JxcZsZ7CbBvdSCBi 4ND0lPgChr3fMfVf9w15tgYA2gpl4YW13K0zmoTBwMOKMpjv0Nb41yd6h0HKJeqAXPKk PTHSyo+WhN0C61xifJe/arN/F5UtG7aHX1gr6a8wmo9bRazR4vbty5UfHtf3IpBIsa07 5776IWaCwk76kubt/3UTyq391dMTpbLhFjUxuVCmjeMGkUcjUD4XW4UwfVbc+4h6dqts irwEtEA9jTEFlVOMxw3c5iFqPGWegzN3rdwwmN4u3ylDokTMOIMdGsuoboJeGtIA5RAJ ExvA== 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=itCXU38GNPssCt/WSnoeX0ePqT6vjs+McfV7VfLaXm0=; b=V2hdSJkQ8PXPLyzwtMpiR5WNDPNBzboGzRLkwcT5STrsmlOOiTp8CJp38yC/g8AueK WuEbAjrdY3gcZvPcCvDh5pwnkyWJWICpNKfuaIWo07/Xud6VvxI8/L2WRT/TXc9826Wj eOjWKqU4NVN1Gtalq2I4wWF0OEcGG+JeL+E5Bbngc0uhGuCqq6pYs0S1wk+zjXiSNEi+ mUm9KF5oo6Bsn0jqu29ow8Y1FimYNo6r/yUCTBhfvf63E6/2DuQx5i+PTk1IN6xd8MqH mBT7i0DPFz6v4AbepgaNc9BdovQSUPExtNZTvqR3F4CNGTFgKzfHMaWsOS1TcchH0IwG H92A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RzruAzof; 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 ht11-20020a170907608b00b0072b83c76e0esi1330314ejc.252.2022.09.06.07.57.13; Tue, 06 Sep 2022 07:57:47 -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=RzruAzof; 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 S241808AbiIFOaB (ORCPT + 99 others); Tue, 6 Sep 2022 10:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242513AbiIFO3a (ORCPT ); Tue, 6 Sep 2022 10:29:30 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 220E392F45 for ; Tue, 6 Sep 2022 06:55:44 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id k80so5601311ybk.10 for ; Tue, 06 Sep 2022 06:55:44 -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=itCXU38GNPssCt/WSnoeX0ePqT6vjs+McfV7VfLaXm0=; b=RzruAzofCMQISZ7x90frSvdR83WhvBYVnd/FIbkqRMYnbBjNIgunhHzImKxDheGcpL OmES4oqH+U6hqJ0648JvYJZ5FJ+XnQkpvpnXYgB/FZ2GHPLpJQ0QN43GPHin/l08XpS+ yD6NvtTAv9ASEpDarkUwqQ7XPSv/6B2AnCvhwYXuozzv1drCaTJQx0wM6RSbsfiLp8vS hTI5vh/Nq7+qwYVeRC0+Wi0CLMRGz4IGkt+KOWpO0jt1yWsiz3o5zKR+ITp0n8AwZI8N LAlFx6LxeWUT6fQvRdtU5fvX6dnqt4hhTbzzQFbyflygaMAJQ3a1DrvR1p63UgA9p9fv B9HQ== 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=itCXU38GNPssCt/WSnoeX0ePqT6vjs+McfV7VfLaXm0=; b=16p/QyZWv0oFrzcQYmhiXqxWQf4ES2ijnrwZhix+mrikNwW4KqiwURyt83BdakzS2y 456heXfeFKHNC1I7s9esFCnUOWdEXt3QIVjTxOd/lTxHmm0A/OWjPyThM1BaUxSwDkDa qWhUxb/N/Wvz2ts1zxmVrTsRHc0EzlBTWdoNilv2DOg6BAHvaWViWnTwP0F0IvZStHBB wFojD3yn7E0yAiX4yqwOKO18PEaBhwHQK61BR6h6O0iDI2n7YBoV29VuuKdoqSu18UPt BrSxSunllEeu+QnXMzjqM/8KCt6dVg2cx2RB1EYPIhsOj5xaIdXPpj6LwfsofP1xLq3u hugg== X-Gm-Message-State: ACgBeo3AMg958xcnV1rpLQTZbpJdpUokc2VS07jN4Qo91+2db3NeXMBH 07+BxVJEGf9wdGBMCGjlkQo0YWRRGvNH9RW9loIV3A== X-Received: by 2002:a25:83d2:0:b0:696:1071:1a01 with SMTP id v18-20020a2583d2000000b0069610711a01mr37353558ybm.335.1662472481680; Tue, 06 Sep 2022 06:54:41 -0700 (PDT) MIME-Version: 1.0 References: <0ecb0a4781be933fcadeb56a85070818ef3566e7.1655761627.git.ashish.kalra@amd.com> In-Reply-To: From: Marc Orr Date: Tue, 6 Sep 2022 06:54:30 -0700 Message-ID: Subject: Re: [PATCH Part2 v6 09/49] x86/fault: Add support to handle the RMP fault for user address To: Jarkko Sakkinen Cc: Borislav Petkov , Ashish Kalra , 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 , "Roth, Michael" , 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=ham 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 On Tue, Sep 6, 2022 at 3:25 AM Jarkko Sakkinen wrote: > > On Tue, Aug 09, 2022 at 06:55:43PM +0200, Borislav Petkov wrote: > > On Mon, Jun 20, 2022 at 11:03:43PM +0000, Ashish Kalra wrote: > > > + pfn = pte_pfn(*pte); > > > + > > > + /* If its large page then calculte the fault pfn */ > > > + if (level > PG_LEVEL_4K) { > > > + unsigned long mask; > > > + > > > + mask = pages_per_hpage(level) - pages_per_hpage(level - 1); > > > + pfn |= (address >> PAGE_SHIFT) & mask; > > > > Oh boy, this is unnecessarily complicated. Isn't this > > > > pfn |= pud_index(address); > > > > or > > pfn |= pmd_index(address); > > I played with this a bit and ended up with > > pfn = pte_pfn(*pte) | PFN_DOWN(address & page_level_mask(level - 1)); > > Unless I got something terribly wrong, this should do the > same (see the attached patch) as the existing calculations. Actually, I don't think they're the same. I think Jarkko's version is correct. Specifically: - For level = PG_LEVEL_2M they're the same. - For level = PG_LEVEL_1G: The current code calculates a garbage mask: mask = pages_per_hpage(level) - pages_per_hpage(level - 1); translates to: >>> hex(262144 - 512) '0x3fe00' But I believe Jarkko's version calculates the correct mask (below), incorporating all 18 offset bits into the 1G page. >>> hex(262144 -1) '0x3ffff'