Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1023902iog; Wed, 15 Jun 2022 18:39:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzD8JmqCQDNMuJW3w1Yh4JLYhzXf99oRr3RjwGgkTaG9liswkqARjMnPtLI+QpNfL2ZK+z X-Received: by 2002:a05:6402:d:b0:431:98fe:c5fd with SMTP id d13-20020a056402000d00b0043198fec5fdmr3384124edu.170.1655343564395; Wed, 15 Jun 2022 18:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655343564; cv=none; d=google.com; s=arc-20160816; b=u0L+XKSYddjlukEBLoKHdJFO8tU5UueuuO8Pai6/gg2F2gNOBYgP0Qb44h/kTi48MG 3/FwzmqRD5MEDETBURD47yRGlKpZGnxfs7oGFVNltXG5c/Mp4EJ/Xl2lL1e0R18CnC9u yKBP03ULsM2NH3heL1YQNyYcLWoVlf6GayltUi5eNWDFIVamSXs4/LRig9j5rRc9F1oB zkkdlHXPBQtfmbWo8osW0CQWHRUXisRalr4muEbhC55sKb8H3u4UyyIPCB3/z2v7KLih xiRBa7Xej3XK4fkacEqYBOUuEh2gK1whZxHcAcaxSnqBmKnoM71t0aOEeFAUa2RdXseh P+bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=r3+kW0xInI0nJeKFWr0j3CIR5eBu259MZNNYczPvc/c=; b=fLYG1Sp/JqkAoThZyLHQyB/tC8iKrTObfpqQAJbgi7WFzl+pbVMUN48piTucuQSyNp 2znGSmqhu4zAPduw6WbQF6OeNpwg7aNbTRunQ7fQXWW4kxO7VqXPnfpRz5J3oITkB4jz jWMuRKUioDSNP1evc5L7V2ja3art26rmPI2mT/nK9MwU3Tcyb33DiW8mzdEdYgyY1SaO ZT1sXoZQ/5voDEwJx64I0s3V6BCs0EykTTBYlsQxh5+lJbXruJFJFwKJso4aMtTkAyBA La9NacXcNEntFS4nGLBfyL84cgZDfy9BCnYWh/k9IlleKvlqANqrALP0PBSmxdds5om0 JxoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hv22ydKQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho8-20020a1709070e8800b00711dd35ed99si410610ejc.652.2022.06.15.18.38.59; Wed, 15 Jun 2022 18:39:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@intel.com header.s=Intel header.b=Hv22ydKQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344660AbiFPBTf (ORCPT + 99 others); Wed, 15 Jun 2022 21:19:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355569AbiFPBTc (ORCPT ); Wed, 15 Jun 2022 21:19:32 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50EE757174 for ; Wed, 15 Jun 2022 18:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655342368; x=1686878368; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=JpkS80tB6/bbnuFv7vHBvQImiWFcwS3sHy76sYiwtUY=; b=Hv22ydKQerAA8N1qqZ6eED7/QDovSpr8iTgwgkzzPfAkfs4yuG1A+5Qc vYJEv9vSAhZ7doklVaA8ymvysuS0dHBNv4XQxftkPq697EhKf21K21o0V utnxiiqG22pT+J0nQOfJXBWs/XKcW3eXltanoqoKkW3XFM+k53CMM5nCV xq/kaefA9n6duhvHhbwA1NoVZJXB5Dlevb9oW5u0n3Zdl08FOARWbzZS3 GgStopoyRZByHoLuv81XsbOlA+xXVS4IlvX9I+vXRAwz3GH3VFvuP/1GT 78c7AJBt+UGel2vkhtxcLTOKmv4MgZtmqGh6cc8gHQRhlE2pWCm5Bpj6p A==; X-IronPort-AV: E=McAfee;i="6400,9594,10379"; a="277934941" X-IronPort-AV: E=Sophos;i="5.91,302,1647327600"; d="scan'208";a="277934941" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2022 18:19:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,302,1647327600"; d="scan'208";a="641296226" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 15 Jun 2022 18:19:22 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 48F02109; Thu, 16 Jun 2022 04:19:26 +0300 (EEST) Date: Thu, 16 Jun 2022 04:19:26 +0300 From: "Kirill A. Shutemov" To: Dave Hansen Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, luto@kernel.org, peterz@infradead.org, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com, seanjc@google.com, thomas.lendacky@amd.com, x86@kernel.org Subject: Re: [PATCHv4 3/3] x86/tdx: Handle load_unaligned_zeropad() page-cross to a shared page Message-ID: <20220616011926.hjmogvbzo6e4d5cj@black.fi.intel.com> References: <20220614120135.14812-1-kirill.shutemov@linux.intel.com> <20220614120135.14812-4-kirill.shutemov@linux.intel.com> <20220615225200.lflv4tbqus6lnj5u@black.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org On Wed, Jun 15, 2022 at 04:34:48PM -0700, Dave Hansen wrote: > On 6/15/22 15:52, Kirill A. Shutemov wrote: > >> + vaddr = (unsigned long)insn_get_addr_ref(&insn, regs); > >> + if (vaddr / PAGE_SIZE != (vaddr + size) / PAGE_SIZE) > > Oops. I just realized it has off-by-one. It supposed to be: > > > > if (vaddr / PAGE_SIZE != (vaddr + size - 1) / PAGE_SIZE) > > That was bugging me. Glad you caught this. > > Wouldn't this be more obviously correct? > > if (ALIGN_DOWN(vaddr, PAGE_SIZE) != > ALIGN_DOWN(vaddr + size, PAGE_SIZE)) > ... I don't think it fixes anything. Consider the case when vaddr is 4092 and size is 4. This is legitimate access -- aligned and not page crosser. The left side of the check will be evaluated to 0 and the right will be 1 which is wrong and will get us -EFAULT. I cannot think of a helper that would fit the need. -- Kirill A. Shutemov