Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1333712rdh; Mon, 25 Sep 2023 09:28:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZzZmbyL69o+Mj2XSY7lmsaKAk/LbZqp515O7ohrBxzzO16qUo5iwWSebBAtqNm5gpDhHl X-Received: by 2002:a17:902:f7c9:b0:1c6:117b:7086 with SMTP id h9-20020a170902f7c900b001c6117b7086mr3925325plw.5.1695659335307; Mon, 25 Sep 2023 09:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695659335; cv=none; d=google.com; s=arc-20160816; b=AKspiEptzCnqIsFvAGKQO5084v7VgwylDVh/+3Odi5RostHs2Q9LdXc9VPdD60Ri0v 4l+WFOQMSNwIf7bnLTVRVp9Mg7geu8FFiJ7j9JVk3nJhcKszi3ocwUXo6Qq1zM4eLA4d gDF0G2Bhe4+y21hjjWAV/rg3qJ9eCRzuaahi+IRQcv1C9cpbkVEcbsYvc+eUcQ1IZm3H Yhn9BogcNFS2TBRDe+iCcbyFjMsqBY88+sn/fSNLm3JtuB0DdrkbiEwArdN3Mmdv0UXV 1iOVj94f+x1lmABZUGnCIxC8d/LRiZqll9GnEvkwMHt5UGdPh+VK9uegC4R2JBeXvhMo /cgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=4bkGT+R94JcQzTSZQhZRpLU0MWXAuYZNqViOddWyog8=; fh=xGT0L07ZRqOubRnjOcwGv0K2z3trOFJMqoFnxmAInVc=; b=BW2TCnYNuVacfcNL92z+CytXwtiLaKhyrcOb8Ye9WRY0PlXyBUHF+MWoZiRGiMFw4P V4500lchIoanwsuxlU3XAmakdohLvRs+JxSxE8rapnk7da6Ds69y7bJP6MsEJooIY1RT eefzkuAKluy9uJJYjJF3JHpsF9M8RRpxyouQ8MRVa5zxvtnd91xE9Fp8KU8gCO07+Dv4 hYZ14DXnXfa4OK624QPZ0eIeJfc1HqACR3UBasRfFSRUySyxOkHWi1S/TXAM6x1oxJG1 mYSexwvkcBuVgLPWvP53L2TAP+othspsigsn39sJnNZL+6CekbSQ5wLfv/l06slblSe+ igbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u12-20020a170902e80c00b001b9eb5d1ea2si11306485plg.198.2023.09.25.09.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 09:28:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 9D0208075292; Mon, 25 Sep 2023 08:16:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232603AbjIYPQ2 (ORCPT + 99 others); Mon, 25 Sep 2023 11:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbjIYPQ0 (ORCPT ); Mon, 25 Sep 2023 11:16:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B6DA99C for ; Mon, 25 Sep 2023 08:16:19 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5FF5FDA7; Mon, 25 Sep 2023 08:16:57 -0700 (PDT) Received: from [10.57.65.61] (unknown [10.57.65.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AFC423F5A1; Mon, 25 Sep 2023 08:16:16 -0700 (PDT) Message-ID: <9f731870-ed36-d2e4-378b-f7fbf338ebd6@arm.com> Date: Mon, 25 Sep 2023 16:16:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2 1/2] KVM: arm64: Add handler for MOPS exceptions Content-Language: en-US To: Marc Zyngier Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Vladimir Murzin , Colton Lewis , linux-kernel@vger.kernel.org References: <20230922112508.1774352-1-kristina.martsenko@arm.com> <20230922112508.1774352-2-kristina.martsenko@arm.com> <87sf734ofv.wl-maz@kernel.org> From: Kristina Martsenko In-Reply-To: <87sf734ofv.wl-maz@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 08:16:27 -0700 (PDT) On 24/09/2023 15:48, Marc Zyngier wrote: > Hi Kristina, Hi Marc, > On Fri, 22 Sep 2023 12:25:07 +0100, > Kristina Martsenko wrote: >> >> An Armv8.8 FEAT_MOPS main or epilogue instruction will take an exception >> if executed on a CPU with a different MOPS implementation option (A or >> B) than the CPU where the preceding prologue instruction ran. In this >> case the OS exception handler is expected to reset the registers and >> restart execution from the prologue instruction. >> >> A KVM guest may use the instructions at EL1 at times when the guest is >> not able to handle the exception, expecting that the instructions will >> only run on one CPU (e.g. when running UEFI boot services in the guest). >> As KVM may reschedule the guest between different types of CPUs at any >> time (on an asymmetric system), it needs to also handle the resulting >> exception itself in case the guest is not able to. A similar situation >> will also occur in the future when live migrating a guest from one type >> of CPU to another. >> >> Add handling for the MOPS exception to KVM. The handling can be shared >> with the EL0 exception handler, as the logic and register layouts are >> the same. The exception can be handled right after exiting a guest, >> which avoids the cost of returning to the host exit handler. >> >> Similarly to the EL0 exception handler, in case the main or epilogue >> instruction is being single stepped, it makes sense to finish the step >> before executing the prologue instruction, so advance the single step >> state machine. > > What is the rationale for advancing the state machine? Shouldn't we > instead return to the guest and immediately get the SS exception, > which in turn gets reported to userspace? Is it because we rollback > the PC to a previous instruction? Yes, because we rollback the PC to the prologue instruction. We advance the state machine so that the SS exception is taken immediately upon returning to the guest at the prologue instruction. If we didn't advance it then we would return to the guest, execute the prologue instruction, and then take the SS exception on the middle instruction. Which would be surprising as userspace would see the middle and epilogue instructions executed multiple times but not the prologue. > In the latter case, won't userspace see multiple SS exceptions for the > middle instruction if trapping from the epilogue? This would be a bit > surprising, to say the least. Not sure I follow. Do you mean multiple in a row or multiple in total? Not in a row (we step the prologue instruction in between), but yes in total (every time we start executing the middle instruction). And this happens when trapping from the middle instruction too, not just the epilogue. Do you see a better way of handling it? Here is an example of what GDB sees when single stepping a guest while the guest executes these instructions ("mops ex" are debug prints in kvm; I've added prologue/main/epilogue comments): Breakpoint 2, 0xffff80008051b6a4 in ?? () 0xffff80008051b6a8 in ?? () # prologue 0xffff80008051b6ac in ?? () # main [ 33.615305] mops ex: memcpy: B->A: fwd: main 0xffff80008051b6a8 in ?? () # prologue 0xffff80008051b6ac in ?? () # main 0xffff80008051b6b0 in ?? () # epilogue [ 34.141251] mops ex: memcpy: A->B: fwd: epi 0xffff80008051b6a8 in ?? () # prologue 0xffff80008051b6ac in ?? () # main 0xffff80008051b6b0 in ?? () # epilogue [ 34.209822] mops ex: memcpy: B->A: fwd: epi 0xffff80008051b6a8 in ?? () # prologue 0xffff80008051b6ac in ?? () # main 0xffff80008051b6b0 in ?? () # epilogue 0xffff80008051b6b4 in ?? () [...] Thanks, Kristina