Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1220918ioo; Fri, 27 May 2022 04:21:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqMy2UvpYU8nqrnGo4Te/2w9zhQkWc+J8AhNHARsO32nldgjfCBc/YD8LZHSgBJ2wQklmp X-Received: by 2002:a05:6a00:1897:b0:518:8bc7:9a82 with SMTP id x23-20020a056a00189700b005188bc79a82mr29669486pfh.26.1653650460328; Fri, 27 May 2022 04:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653650460; cv=none; d=google.com; s=arc-20160816; b=FxXf8aEVfPKjBTMt3H6hUQLpO7tFsFnt0MFt9SQlEzdniyL1AtDgIrrXq+lz13+xdD v9TzJ7NGvtfaq6aUvVVs14JGA6d9YEF02HMBXyCN/IZYMMy+YZ3lUjU97fuKIE6I0hMn mGIowqiiIH7XurZwai3fWdAGQglAFMp8BNCKH6ZHYfVEqjO+x4dWGjYm/LNR0hAg57X2 y2BKDufpqvjVN7tA+VhEzsQqIY84JfXY6udbbvrrN/QmB599iuKuDQdmWt8X5YoRZbqg R3tzd7gQDg79TcdguaChsn5VowNtR6rcbNlc5WVIFdbGocWjFxxRLfKpF5AqsHWi0NGJ CkJg== 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=FPVnNMIwh1G4VDOsRR074Jijnt5efag+MR+Y3p3/mFM=; b=NZGyzcqLIBlZAaTfzVN1VSvdLrn925D2cpsfrAn4yPPpGCO2mSqiwI7vO1M3TRWutw k7m87ioOJw+OYpxDxtz/l78IJB5QFROCCYEAH7l8h0ozqBXkld9RsNTnPuzRSXViQ0zO gqWw7rLMGmQWakgKWaVRIPDfZaEeEttOr12AK1vNMnmmWnsAFk5B3iFbLZowfxS/0iqa 6J/0oXkGcnOBus9L3vjqlXv+smlQoAnmMuANOZnX8a1l34zQN8vb1VE5NBwtPDGNUmoE pRRrz3sUnIDvFq77/vxLSpnYuGEUxCIG1LvMmdKNTCAFN1rZ1sSt143jQQ7Nj6hqHe++ 5P7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KNAHQXbd; 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 k6-20020a170902ce0600b00156bdbdedf4si5118141plg.269.2022.05.27.04.20.42; Fri, 27 May 2022 04:21:00 -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=KNAHQXbd; 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 S1347852AbiEZUOA (ORCPT + 99 others); Thu, 26 May 2022 16:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbiEZUN6 (ORCPT ); Thu, 26 May 2022 16:13:58 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BC77C1EC4 for ; Thu, 26 May 2022 13:13:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653596037; x=1685132037; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=0J3P8mCVmRJH4VExXC4e3LOi9we7yQ54YNUzVR9BQ9Y=; b=KNAHQXbdTFieoE8nYXOJdPw3snxuBQwxOYcMTDVcvKK6pdQOWJUTg6Kd gVbZryAm7+JMZMFtnMaufscDCoaon0pY0EEEPH79GZhxwBx+JOBHAx3z4 rsmLj5S7uS6Mx/lGR7hfBn5Q9yXncZQzn8x5ojCGfx0OFb4zkzd/vCfRH 5jDsSrKwHjA7PrsVIygAnaVyue9gmXkliSDXDa3+I2d16ziYcd9u7eFZf vtUeVx3k17mlQ4y7ohm1prPfvVbfKT8czApX7yMkXZqkNU8A/zugHHsQS bK1AEinlgPelU+HE0zKbeKRqYN3pRyVwKRIoAFSPNMjT+c+nzB9s1MurF Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10359"; a="274279075" X-IronPort-AV: E=Sophos;i="5.91,252,1647327600"; d="scan'208";a="274279075" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2022 13:13:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,252,1647327600"; d="scan'208";a="902196364" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 26 May 2022 13:13:53 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id F1E04109; Thu, 26 May 2022 23:13:54 +0300 (EEST) Date: Thu, 26 May 2022 23:13:54 +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: [PATCHv3 2/3] x86/tdx: Clarify RIP adjustments in #VE handler Message-ID: <20220526201354.v5a6fsi4aiuet2d7@black.fi.intel.com> References: <20220524221012.62332-1-kirill.shutemov@linux.intel.com> <20220524221012.62332-3-kirill.shutemov@linux.intel.com> <89f55141-a71c-1fd8-e1be-96355c63c03a@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <89f55141-a71c-1fd8-e1be-96355c63c03a@intel.com> X-Spam-Status: No, score=-5.0 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, May 25, 2022 at 09:02:48AM -0700, Dave Hansen wrote: > On 5/24/22 15:10, Kirill A. Shutemov wrote: > > +static int ve_instr_len(struct ve_info *ve) > > +{ > > + /* > > + * If the #VE happened due to instruction execution, GET_VEINFO > > + * provides info on the instruction. > > + * > > + * For #VE due to EPT violation, info provided by GET_VEINFO not usable > > + * and kernel has to decode instruction manually to find out its > > + * length. Catch such cases. > > + */ > > + if (WARN_ON_ONCE(ve->exit_reason == EXIT_REASON_EPT_VIOLATION)) > > + return 0; > > + > > + return ve->instr_len; > > +} > > I'm not super happy with how this comment ended up. First, let's put > the comment next to the code to which it applies, like: > > /* > * ve->instr_len is not defined for EPT violations. For those, > * the kernel must decode instructions manually and should not > * be using this function. > */ > if (WARN_ON_ONCE(ve->exit_reason == EXIT_REASON_EPT_VIOLATION)) > return 0; > > /* > * Assume that the #VE occurred due to instruction execution. > */ > return ve->instr_len; Would it be helpful if the function has a whitelist of exit resons where using ve->instr_len is safe? WARN_ONCE() and return 0 otherwise. -- Kirill A. Shutemov