From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 812FBC10F03 for ; Thu, 25 Apr 2019 13:04:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1BAA20678 for ; Thu, 25 Apr 2019 13:04:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="c845FDx1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1BAA20678 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2gCGubcWOWyoFkpUseBhyMWURX04TVMPpiVppaiu3YU=; b=c845FDx11Ah+ct ctpFUljswCFVW+d6kFiQAsnQ2qwIOTIzDGy6rrICNhHYtTA1qS2HVtQEAAPB7Sunnlr8X9Ns/+HYs MsRR55q1qokM8NKBW2L1K5HiKyMlr1lnl43EmD4FvfiJLpy/0ey6wowf4zbupKhx0cVSC4L4LtSZC OjZHxxbUiXGqXiMuGrpWjiNRkxA2wOFDMkyU7dqS2LjOlp27U9nZHefYKflQjn5F5CpLa3PyPp+tn M2U42KGYUvijuZIcAGyfUj4oMISpMu6VQlF42OExayIHBY+pAwGI2HxWBmhfdcUHPniLweZOa1WwR 4BPEuOJEUSP347VcoRVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJe3I-0002zO-0b; Thu, 25 Apr 2019 13:04:36 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJe3E-0002yv-PQ for linux-arm-kernel@lists.infradead.org; Thu, 25 Apr 2019 13:04:34 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB2BDA78; Thu, 25 Apr 2019 06:04:31 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C547E3F5C1; Thu, 25 Apr 2019 06:04:29 -0700 (PDT) Date: Thu, 25 Apr 2019 14:04:27 +0100 From: Dave Martin To: Alex =?iso-8859-1?Q?Benn=E9e?= Subject: Re: [PATCH v2 07/14] KVM: arm64/sve: Make register ioctl access errors more consistent Message-ID: <20190425130424.GA3567@e103592.cambridge.arm.com> References: <1555603631-8107-1-git-send-email-Dave.Martin@arm.com> <1555603631-8107-8-git-send-email-Dave.Martin@arm.com> <877ebiw9lm.fsf@zen.linaroharston> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <877ebiw9lm.fsf@zen.linaroharston> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190425_060432_833850_17502BEF X-CRM114-Status: GOOD ( 25.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Okamoto Takayuki , Christoffer Dall , Ard Biesheuvel , Marc Zyngier , Catalin Marinas , Will Deacon , Zhang Lei , Julien Grall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Apr 25, 2019 at 01:30:29PM +0100, Alex Benn=E9e wrote: > = > Dave Martin writes: > = > > Currently, the way error codes are generated when processing the > > SVE register access ioctls in a bit haphazard. > > > > This patch refactors the code so that the behaviour is more > > consistent: now, -EINVAL should be returned only for unrecognised > > register IDs or when some other runtime error occurs. -ENOENT is > > returned for register IDs that are recognised, but whose > > corresponding register (or slice) does not exist for the vcpu. > > > > To this end, in {get,set}_sve_reg() we now delegate the > > vcpu_has_sve() check down into {get,set}_sve_vls() and > > sve_reg_to_region(). The KVM_REG_ARM64_SVE_VLS special case is > > picked off first, then sve_reg_to_region() plays the role of > > exhaustively validating or rejecting the register ID and (where > > accepted) computing the applicable register region as before. > > > > sve_reg_to_region() is rearranged so that -ENOENT or -EPERM is not > > returned prematurely, before checking whether reg->id is in a > > recognised range. > > > > -EPERM is now only returned when an attempt is made to access an > > actually existing register slice on an unfinalized vcpu. > > > > Fixes: e1c9c98345b3 ("KVM: arm64/sve: Add SVE support to register acces= s ioctl interface") > > Fixes: 9033bba4b535 ("KVM: arm64/sve: Add pseudo-register for the guest= 's vector lengths") > > Suggested-by: Andrew Jones > > Signed-off-by: Dave Martin > > Reviewed-by: Andrew Jones [...] > > @@ -335,25 +344,30 @@ static int sve_reg_to_region(struct sve_state_reg= _region *region, > > /* Verify that we match the UAPI header: */ > > BUILD_BUG_ON(SVE_NUM_SLICES !=3D KVM_ARM64_SVE_MAX_SLICES); > > > > - if ((reg->id & SVE_REG_SLICE_MASK) > 0) > > - return -ENOENT; > > - > > - vq =3D sve_vq_from_vl(vcpu->arch.sve_max_vl); > > - > > reg_num =3D (reg->id & SVE_REG_ID_MASK) >> SVE_REG_ID_SHIFT; > > > > if (reg->id >=3D zreg_id_min && reg->id <=3D zreg_id_max) { > > + if (!vcpu_has_sve(vcpu) || (reg->id & SVE_REG_SLICE_MASK) > 0) > > + return -ENOENT; > > + > > + vq =3D sve_vq_from_vl(vcpu->arch.sve_max_vl); > > + > > reqoffset =3D SVE_SIG_ZREG_OFFSET(vq, reg_num) - > > SVE_SIG_REGS_OFFSET; > > reqlen =3D KVM_SVE_ZREG_SIZE; > > maxlen =3D SVE_SIG_ZREG_SIZE(vq); > > } else if (reg->id >=3D preg_id_min && reg->id <=3D preg_id_max) { > > + if (!vcpu_has_sve(vcpu) || (reg->id & SVE_REG_SLICE_MASK) > 0) > > + return -ENOENT; > > + > > + vq =3D sve_vq_from_vl(vcpu->arch.sve_max_vl); > > + > = > I suppose you could argue for a: > = > if (reg->id >=3D zreg_id_min && reg->id <=3D preg_id_max) { > if (!vcpu_has_sve(vcpu) || (reg->id & SVE_REG_SLICE_MASK) > 0) > return -ENOENT; > = > vq =3D sve_vq_from_vl(vcpu->arch.sve_max_vl); > = > if (reg->id <=3D zreg_id_max) { > reqoffset =3D SVE_SIG_ZREG_OFFSET(vq, reg_num) - > SVE_SIG_REGS_OFFSET; > reqlen =3D KVM_SVE_ZREG_SIZE; > maxlen =3D SVE_SIG_ZREG_SIZE(vq); > } else { > reqoffset =3D SVE_SIG_PREG_OFFSET(vq, reg_num) - > SVE_SIG_REGS_OFFSET; > reqlen =3D KVM_SVE_PREG_SIZE; > maxlen =3D SVE_SIG_PREG_SIZE(vq); > } > } else { > return -EINVAL; > } > = > but only for minimal DRY reasons. Agreed, but that bakes in another assumption: that the ZREG and PREG ID ranges are contiguous. I preferred to keep the number of assumptions down. Althoug the resulting code wasn't ideal, the actual amount of duplication that I ended up with here seemed low enough as to be acceptable (though opinions can differ on that). [...] Cheers ---Dave _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel