From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33AF92192FC for ; Wed, 18 Jun 2025 22:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750286615; cv=none; b=IpUSilrh55sRQPxGTrHwqMPHbT6FHp98PHZ/oyMiFVnXVeAKouNgoZ7lKHq9Bcr8LmGJqXQymjauBUApenYBOHHz+8nh2THhghejmAEXtVuoNfalUtObvMOUKMOdu+Fa++jJtOh3wnTDuMFrBiqqZXoK/Vs6V+T5/jrQMKFDcYc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750286615; c=relaxed/simple; bh=Iy+Ox/bH+mj99voHVuFYFLezAqT1Ea3TUU/gpHbZh4M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qVgdOrD+kbLLxsDuy4jBazKPgnVbZ9+GkFWhYun0yhgoqqCbdrFGubEHZ7xQG5GZf+GkwwHFM9i9uENtOkAU61Ok8DRYRuXDW3zQhL0YBVmBNB+iMFNZH4MrqTPulh6O24/anQy3yyjoAk+cb3XYAK/cziQvI2e/huiNkmt3fm0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=EpbLDF+7; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="EpbLDF+7" Date: Wed, 18 Jun 2025 15:43:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1750286611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iabUtXH2S5hgnNxipXhGWLLQltCqncktdrGikSQJGv8=; b=EpbLDF+7NjqZog0McGJwo+5HvohOHNAQ8BaL7lZ03J7iJoDBrg8lFG2S6I9VFIMY3Gd8yJ kTLle8vGIij2bB5f/LXeRE9tYV0K5nhLvNCmRGtvD2HcKQJ6cqzHDwB2+zkiC1Sgge9yZn 6Pp85WKy351lqpG6lvz+IzpntWkiNOc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: James Houghton , Paolo Bonzini , Jonathan Corbet , Marc Zyngier , Yan Zhao , Nikita Kalyazin , Anish Moorthy , Peter Gonda , Peter Xu , David Matlack , wei.w.wang@intel.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v3 04/15] KVM: Add common infrastructure for KVM Userfaults Message-ID: References: <20250618042424.330664-1-jthoughton@google.com> <20250618042424.330664-5-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Wed, Jun 18, 2025 at 01:33:17PM -0700, Sean Christopherson wrote: > On Wed, Jun 18, 2025, Oliver Upton wrote: > > > Signed-off-by: Sean Christopherson > > No need for my SoB. > > > > +#ifdef CONFIG_KVM_GENERIC_PAGE_FAULT > > > +bool kvm_do_userfault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) > > > > The polarity of the return here feels weird. If we want a value of 0 to > > indicate success then int is a better return type. > > The boolean is my fault/suggestion. My thinking is that it would make the callers > more intuitive, e.g. so that this reads "if do userfault, then exit to userspace > with -EFAULT". > > if (kvm_do_userfault(vcpu, fault)) > return -EFAULT; Agreed, this reads correctly. My only issue is that when I read the function signature, "bool" is usually wired the other way around. > > > +{ > > > + struct kvm_memory_slot *slot = fault->slot; > > > + unsigned long __user *user_chunk; > > > + unsigned long chunk; > > > + gfn_t offset; > > > + > > > + if (!kvm_is_userfault_memslot(slot)) > > > + return false; > > > + > > > + offset = fault->gfn - slot->base_gfn; > > > + user_chunk = slot->userfault_bitmap + (offset / BITS_PER_LONG); > > > + > > > + if (__get_user(chunk, user_chunk)) > > > + return true; > > And this path is other motiviation for returning a boolean. To me, return "success" > when a uaccess fails looks all kinds of wrong: > > if (__get_user(chunk, user_chunk)) > return 0; Yeah, that's gross. Although I would imagine we want to express "failure" here, game over, out to userspace for resolution. So maybe: if (__get_user(chunk, user_chunk)) return -EFAULT; > That said, I don't have a super strong preference; normally I'm fanatical about > not returning booleans. :-D +1, it isn't _that_ big of a deal, just noticed it as part of review. Thanks, Oliver