From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756677AbbCCTtH (ORCPT ); Tue, 3 Mar 2015 14:49:07 -0500 Received: from mail-bn1on0112.outbound.protection.outlook.com ([157.56.110.112]:46910 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754306AbbCCTtF convert rfc822-to-8bit (ORCPT ); Tue, 3 Mar 2015 14:49:05 -0500 X-WSS-ID: 0NKNJ1M-07-9EG-02 X-M-MSG: Message-ID: <54F61029.3060101@amd.com> Date: Tue, 3 Mar 2015 13:48:57 -0600 From: Joel Schopp User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= CC: Gleb Natapov , Paolo Bonzini , , David Kaplan , Joerg Roedel , , Borislav Petkov Subject: Re: [PATCH v3] x86: svm: use kvm_fast_pio_in() References: <20150302210202.2951.56810.stgit@joelvmguard2.amd.com> <20150303164235.GB2494@potion.brq.redhat.com> In-Reply-To: <20150303164235.GB2494@potion.brq.redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Originating-IP: [10.180.168.240] X-EOPAttributedMessage: 0 Authentication-Results: spf=none (sender IP is 165.204.84.221) smtp.mailfrom=Joel.Schopp@amd.com; 8bytes.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:165.204.84.221;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(428002)(51704005)(86362001)(59896002)(2950100001)(65806001)(65956001)(54356999)(50466002)(77096005)(77156002)(83506001)(62966003)(19580395003)(80316001)(87936001)(47776003)(76176999)(64126003)(92566002)(65816999)(106466001)(87266999)(50986999)(23676002)(110136001)(46102003)(53416004)(105586002)(101416001)(5820100001)(33656002)(36756003);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR02MB479;H:atltwp01.amd.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR02MB479; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006);SRVR:DM2PR02MB479; X-Forefront-PRVS: 0504F29D72 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:DM2PR02MB479; X-OriginatorOrg: amd4.onmicrosoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2015 19:49:00.5152 (UTC) X-MS-Exchange-CrossTenant-Id: fde4dada-be84-483f-92cc-e026cbee8e96 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fde4dada-be84-483f-92cc-e026cbee8e96;Ip=[165.204.84.221] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR02MB479 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thank you for your detailed review on several of my patches. >> >> +static int complete_fast_pio(struct kvm_vcpu *vcpu) > (complete_fast_pio_in()?) If I do a v4 I'll adopt that name. >> +{ >> + unsigned long new_rax = kvm_register_read(vcpu, VCPU_REGS_RAX); > Shouldn't we handle writes in EAX differently than in AX and AL, because > of implicit zero extension. I don't think the implicit zero extension hurts us here, but maybe there is something I'm missing that I need understand. Could you explain this further? > >> + >> + BUG_ON(!vcpu->arch.pio.count); >> + BUG_ON(vcpu->arch.pio.count * vcpu->arch.pio.size > sizeof(new_rax)); > (Looking at it again, a check for 'vcpu->arch.pio.count == 1' would be > sufficient.) I prefer the checks that are there now after your last review, especially since surrounded by BUG_ON they only run on debug kernels. > >> + >> + memcpy(&new_rax, vcpu, sizeof(new_rax)); >> + trace_kvm_pio(KVM_PIO_IN, vcpu->arch.pio.port, vcpu->arch.pio.size, >> + vcpu->arch.pio.count, vcpu->arch.pio_data); >> + kvm_register_write(vcpu, VCPU_REGS_RAX, new_rax); >> + vcpu->arch.pio.count = 0; > I think it is better to call emulator_pio_in_emulated directly, like > > emulator_pio_in_out(&vcpu->arch.emulate_ctxt, vcpu->arch.pio.size, > vcpu->arch.pio.port, &new_rax, 1); > kvm_register_write(vcpu, VCPU_REGS_RAX, new_rax); > > because we know that vcpu->arch.pio.count != 0. I think two extra lines of code in my patch vs your suggestion are worth it to a) reduce execution path length b) increase readability c) avoid breaking the abstraction by not checking the return code d) avoid any future bugs introduced by changes the function that would return a value other than 1. > > Refactoring could avoid the weird vcpu->ctxt->vcpu conversion. > (A better name is always welcome.) The pointer chasing is making me dizzy. I'm not sure why emulator_pio_in_emulated takes a x86_emulate_ctxt when all it does it immediately translate that to a vcpu and never use the x86_emulate_ctxt, why not pass the vcpu in the first place?