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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81958C43334 for ; Tue, 12 Jul 2022 07:25:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 03BCA4BDD9; Tue, 12 Jul 2022 03:25:25 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iI9sgl+LXfjT; Tue, 12 Jul 2022 03:25:23 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C735A4BD4F; Tue, 12 Jul 2022 03:25:23 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 065D940B90 for ; Tue, 12 Jul 2022 03:25:23 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QXPdxvsi6A9Y for ; Tue, 12 Jul 2022 03:25:21 -0400 (EDT) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id CCBFC40B6C for ; Tue, 12 Jul 2022 03:25:21 -0400 (EDT) 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 2099B614A3; 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 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") 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 Cc: kvm@vger.kernel.org, Schspa Shi , Oliver Upton , kernel-team@android.com, kvmarm@lists.cs.columbia.edu, Linux ARM X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu 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. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm