Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4233580ybf; Tue, 3 Mar 2020 23:31:17 -0800 (PST) X-Google-Smtp-Source: ADFU+vtiQlTIL4uCY4kkszaYagsM/HzwwR33gSHG5TyR6L3JQdJ07jhz8oKEB8Fs+jFqv+mLtVFV X-Received: by 2002:a05:6830:23b9:: with SMTP id m25mr335519ots.354.1583307077392; Tue, 03 Mar 2020 23:31:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583307077; cv=none; d=google.com; s=arc-20160816; b=unAr/tpZl/LewxBu6zRZgnTrhCD/qyMiY5UyoYC8p+AOZy/hK7vLcVO/UnTlNgEmK1 8M7EM5C1osLcf1HkAtzo0yDc509+RTAxeqx2ltEH4cWkLGYliAxMzD0PSW+ySNsju5HW 6OrK2YUEt7bJcIMt5Vo2JzFkyBw6Q0z6brjT5leAVoEnkrw+1l3mA2STLZnueSFxYR+U ERBNGhHELj9wUXWAl8dbcSqCPtzZuWe0K78PYo9BkIeiQDl23i+c+E3JK8rpF/tkIvzw tiTCfUARkFilXrIxdfsAC0LJX/kusdcDD6vSbc//h7/hIfQlL/hVO3MvM3JGUmqM6Yfm bpiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=T+pL0qsagmn9LfFxvyydb0rWSBt5iVBDnHKUDsA/QhY=; b=trXUn2N85PkbiVTiR0U2GYgirkJewMKe4in60RlbipGXvV3ApvMveA0GY7HBLA0RZo ibIROxY3fsg72WPzINR/VVJC/lbXRNUMvu6l+x3lC/ckehMUSva7WF5w5ZvXQREMoJGq XCnMnwBywOEOzo3HEMk2Qa9jquH0LhYvYl3X8aqGJOZUin3YHwJM6NlQ90jtTJDJesvG hyTIUK+gI1NdbX79zp0Zdb6YceSVOLGPI2kcyrhdnJsql5Lie964YA9Iu/ST4U+sOqt6 LVTnQapaAbdXYuOrRKdiYEzAxRjrmGGvkpy3orIivGoCgfkRJDkuz7M5BQtooyJhSOSY he0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z4VKmwS5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t25si692587otl.317.2020.03.03.23.31.06; Tue, 03 Mar 2020 23:31:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z4VKmwS5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728588AbgCDHa6 (ORCPT + 99 others); Wed, 4 Mar 2020 02:30:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:31693 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728216AbgCDHa6 (ORCPT ); Wed, 4 Mar 2020 02:30:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583307056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T+pL0qsagmn9LfFxvyydb0rWSBt5iVBDnHKUDsA/QhY=; b=Z4VKmwS5MnB4I7qAuwjv3siYJ5PX/6g/bioX2sd4C/bCWM+niOvwvTtkZHKKov0v3MYSnS QaDAEZvjec3++9LKlP5/WAwVqEpelglZpw5pWx/yJ4KQurSgVl7yrY9XDZSSB5eRNUPQxd 4QOuhh1lfG4a5B1iFyRQe/BDpcw3Qo4= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-147-5D2zWrqSPGGp5ciQd4hA5g-1; Wed, 04 Mar 2020 02:30:53 -0500 X-MC-Unique: 5D2zWrqSPGGp5ciQd4hA5g-1 Received: by mail-wm1-f70.google.com with SMTP id r19so501761wmh.1 for ; Tue, 03 Mar 2020 23:30:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=T+pL0qsagmn9LfFxvyydb0rWSBt5iVBDnHKUDsA/QhY=; b=lMW+EWzXnYVM8Th/r5tfqTJkUzqt966e1Mskv5MgHQHtwwQE7zgWnLQtl1kpKwXZTm v5fMHiTjNlf1FNtVmOnQ1zZsgmh1OJgDMdSdacMgrtJqJCSVdji2pOK/dK7VNZKt9+gh +VGR6ELZGZpjsiTRmoYVmCRarDcEOUazeEihRW0LPiZC87/Qs6x4LmD3UR0bi9n23U2c 2OE7pzEQ8LzumMiTH3WZS9XW3ILs8l/3w/wFdOcSb9kd0k+37Jt8DiZvHLMgWJyI7ScU LYShGu5IuwIhaaypyLNtQi666atNYLXK/a2TfwL/TAJyk3/ZX1A0El8mvana6WUnO29Z rHJg== X-Gm-Message-State: ANhLgQ3tOFTN9xASg/F/VcNycUmPjY2AVocUyXavSSI2Q664kSc/ILGB f1dc4tACRO4nQa+yjEaTN+GsJsAmluSUJgma99HKT9DLVvdcYUNaXJtGb0bsgKEhQ5NWS72VGld WI8fk8Qx1WxIPCQmxrmOqo1CL X-Received: by 2002:adf:de83:: with SMTP id w3mr2620122wrl.275.1583307051533; Tue, 03 Mar 2020 23:30:51 -0800 (PST) X-Received: by 2002:adf:de83:: with SMTP id w3mr2620105wrl.275.1583307051303; Tue, 03 Mar 2020 23:30:51 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:9def:34a0:b68d:9993? ([2001:b07:6468:f312:9def:34a0:b68d:9993]) by smtp.gmail.com with ESMTPSA id y3sm2982342wmi.14.2020.03.03.23.30.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Mar 2020 23:30:49 -0800 (PST) Subject: Re: [PATCH] KVM: X86: Avoid explictly fetch instruction in x86_decode_insn() To: linmiaohe , Peter Xu Cc: Sean Christopherson , Vitaly Kuznetsov , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" References: <05ca4e7e070844dd92e4f673a1bc15d9@huawei.com> From: Paolo Bonzini Message-ID: <593e16d8-1021-29ef-11d0-a72d762db057@redhat.com> Date: Wed, 4 Mar 2020 08:30:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <05ca4e7e070844dd92e4f673a1bc15d9@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/03/20 03:37, linmiaohe wrote: > Hi: > Peter Xu writes: >> insn_fetch() will always implicitly refill instruction buffer properly when the buffer is empty, so we don't need to explicitly fetch it even if insn_len==0 for x86_decode_insn(). >> >> Signed-off-by: Peter Xu >> --- >> arch/x86/kvm/emulate.c | 5 ----- >> 1 file changed, 5 deletions(-) >> >> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index dd19fb3539e0..04f33c1ca926 100644 >> --- a/arch/x86/kvm/emulate.c >> +++ b/arch/x86/kvm/emulate.c >> @@ -5175,11 +5175,6 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) >> ctxt->opcode_len = 1; >> if (insn_len > 0) >> memcpy(ctxt->fetch.data, insn, insn_len); >> - else { >> - rc = __do_insn_fetch_bytes(ctxt, 1); >> - if (rc != X86EMUL_CONTINUE) >> - goto done; >> - } >> >> switch (mode) { >> case X86EMUL_MODE_REAL: This is a a small (but measurable) optimization; going through __do_insn_fetch_bytes instead of do_insn_fetch_bytes is a little bit faster because it lets you mark the branch in do_insn_fetch_bytes as unlikely, and in general it allows the branch predictor to do a better job. Paolo > Looks good, thanks. But it seems we should also take care of the comment in __do_insn_fetch_bytes(), as we do not > load instruction at the beginning of x86_decode_insn() now, which may be misleading: > /* > * One instruction can only straddle two pages, > * and one has been loaded at the beginning of > * x86_decode_insn. So, if not enough bytes > * still, we must have hit the 15-byte boundary. > */ > if (unlikely(size < op_size)) > return emulate_gp(ctxt, 0); >