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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 358E3C433EF for ; Tue, 12 Jul 2022 07:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232242AbiGLHZY (ORCPT ); Tue, 12 Jul 2022 03:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbiGLHZW (ORCPT ); Tue, 12 Jul 2022 03:25:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 917CC2CE28 for ; Tue, 12 Jul 2022 00:25:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 26C38614E7 for ; Tue, 12 Jul 2022 07:25:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7ED52C3411E; Tue, 12 Jul 2022 07:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657610720; bh=YKaCqMKd1XPgMKAxblXwt/S2AkClHwvUTcLh0D9pkiA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XGvyNRRu3pU53t6y/oNVjI09Ghr4IkySsWY0dIdpy/uveL9OHxOLuDReIR5b1R6UD B1CkkZYY33tMKqmwqs7vBctVuOnaDnhcVRWTpkjATuwXYSpBAPFOJneGkfCwmI92Di qeiX41DVh5yxGrQWPRCpPp3qka7HnihM1bS9nFHfflbvCoBdZySa020pYXb+ofRKsC QHnXo2JWid3kx8qb8CK1U5hnGF3uY9ax41qZvMTZnEPUUfmN9gARzkiX5k1e6D2sck ngXcDJSrgwyQvIU00XHFUT/wbFWfADrZz/+pqLCWldy1kxH6f9LG4wgrspPQyRI2wG vaJXh58+ZZZvA== Received: from ip-185-104-136-29.ptr.icomera.net ([185.104.136.29] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oBAGj-006rNw-Rg; Tue, 12 Jul 2022 08:25:18 +0100 Date: Tue, 12 Jul 2022 08:25:09 +0100 Message-ID: <87edyqlrmy.wl-maz@kernel.org> From: Marc Zyngier To: Reiji Watanabe Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux ARM , Schspa Shi , kernel-team@android.com, Oliver Upton Subject: Re: [PATCH 05/19] KVM: arm64: Consolidate sysreg userspace accesses In-Reply-To: References: <20220706164304.1582687-1-maz@kernel.org> <20220706164304.1582687-6-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.104.136.29 X-SA-Exim-Rcpt-To: reijiw@google.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, schspa@gmail.com, kernel-team@android.com, oliver.upton@linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Hi Reiji, On Sat, 09 Jul 2022 07:55:08 +0100, Reiji Watanabe wrote: > > Hi Marc, [...] > > @@ -2854,17 +2794,28 @@ static int demux_c15_set(u64 id, void __user *uaddr) > > int kvm_sys_reg_get_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, > > const struct sys_reg_desc table[], unsigned int num) > > { > > - void __user *uaddr = (void __user *)(unsigned long)reg->addr; > > + u64 __user *uaddr = (u64 __user *)(unsigned long)reg->addr; > > const struct sys_reg_desc *r; > > + u64 val; > > + int ret; > > > > r = id_to_sys_reg_desc(vcpu, reg->id, table, num); > > if (!r) > > return -ENOENT; > > > > - if (r->get_user) > > - return (r->get_user)(vcpu, r, reg, uaddr); > > + if (r->get_user) { > > + ret = (r->get_user)(vcpu, r, &val); > > + } else { > > + val = __vcpu_sys_reg(vcpu, r->reg); > > + ret = 0; > > + } > > + > > + if (!ret) { > > + if (put_user(val, uaddr)) > > + ret = -EFAULT; > > Nit: Since put_user() returns -EFAULT when it fails, > we can simply set 'ret' to the return value from put_user(). Indeed. I've now reworked all the instances of this that survive the incremental rework. Thanks for the suggestion. > (same for get_user()) This one is a harder sell, as get_user() usually occurs at the beginning of the function, without a preexisting error context. > > Reviewed-by: Reiji Watanabe > > I like this fix! Thanks! M. -- Without deviation from the norm, progress is not possible.