Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6253193iog; Thu, 23 Jun 2022 14:57:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1saqOiKKCgzP93SnOkPN+mWNHuT10INHkU5rAbXXY7bYDiy9H43pOQuvIDLheidRIaQeJyY X-Received: by 2002:a17:907:868c:b0:722:bc0b:500e with SMTP id qa12-20020a170907868c00b00722bc0b500emr10590368ejc.703.1656021436271; Thu, 23 Jun 2022 14:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656021436; cv=none; d=google.com; s=arc-20160816; b=rRlQ38YO/k6lwBA4aZVowuYfjaLjUq0r5X4vjLxm5+wxqJjcyB24hvKWaXCxPAoEbB Mc2KtLL13YCjSJYJLsA0SPQdGvEox0mzNlUuWKsGB2mIGDOYXihxqsQVhc9ndleuSERX b4r84nyIhc9baqGnu6z3ILmVJRC9Q7jMRVoJhAVWe4zldxXVb3KMmSJoEzKj63+j6cHP mNoz7GtYw5N0eTMkpEwP9h0U6FUkMNUydZ2ZkSvsO/sHs5c/dEPHJMIZcp9swdLyXVvs LAmr0X+uE6NTYYVeL7eeZ44wVu6XRFZnulDixQyU+JtjO5GD/gwGgmaTpBJO0nk+Nwok TVGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WP+rwC4TGDAfQrrpdmxtx5HaFMWvuSkA5tpFa2Z0KTo=; b=NgkivzP5QOstXmpxzL+0HDOQ9/t+ODo83xawsmAKDHoKRCNfHXc0RwMbkgxa2DYX8V ABs8jd2wOrYtQXobEnF+NuFLK8bUxG2I4FjzYblx3N5xcv+YsExAiwVViNiIyjy6RqdB PjZq4jIlC1jT3tjN33aDqPnPhgcrze8IBDEtMzN+SbAH6XfOEAp8rpjzdimgZW4+dJqY UdTlrj8K15cLfHBjTQB7VXPbRM+t0jgniyaml8RB/Or1mICIOIrnk94p1IG+MsUAJoa6 mqnbHS4VvWM4PNKMX0eHK4hdUmoAYvB27lIq50YlxP7qnlBp8mFDUTZ/8sScQOBttWp6 HGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FaIYrEPF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a05640235c200b0043581fb3d83si1003640edc.279.2022.06.23.14.56.37; Thu, 23 Jun 2022 14:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FaIYrEPF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229743AbiFWVwp (ORCPT + 99 others); Thu, 23 Jun 2022 17:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbiFWVwo (ORCPT ); Thu, 23 Jun 2022 17:52:44 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56886609D7 for ; Thu, 23 Jun 2022 14:52:43 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id q18so373222pld.13 for ; Thu, 23 Jun 2022 14:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=WP+rwC4TGDAfQrrpdmxtx5HaFMWvuSkA5tpFa2Z0KTo=; b=FaIYrEPF7pH2Sg//kKmJsf4O808sp8hU3xWztRq7PW/NTqPPLAtvMC+D62zDoo+Hfo nD4lTJVJCNX6DnRqCnafQOpaZ8N3Ie155liv3aGLaVYMelGO1Mt51ztufJGskpU8fqgH soA/5thJgCOY4jOHBZt46Rh5pmOj6zNvlG4mmfvzHKkPscBNoRjStOvA/rY0qDp7PcGE /RPTM4wLwtu067izgHGTSTyu49NPFzY1X6noKkMnKFZzk623WewYhW1yMNqhhGq5xNVU /0m14dFYj73PPdK7f1clf1vXrU0z0O/T7MeJ4hLanIN4KJJk1axvx7cDOqXDjF0as+QH 21vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=WP+rwC4TGDAfQrrpdmxtx5HaFMWvuSkA5tpFa2Z0KTo=; b=ZsWEgpk9RB4i9zpcrMZ/xU4kRsVZ1qqqqkX2f2tgjKNiYAwt44ndv1zbChRKontZ4v NbmxXpxLje0IvNPLIRhzgdG7bdGfzjFjAlvykvgQIdelTvMeVTcxojBRDFTk0733Prr7 GY6zaGni28VgAlpOqFxh5/D2Ss/wUEkrEjOjPqJ+bMC1rZApaJiZr+Fk7azYmlS9jddK iS+rTStsFMPo4/JRvOaoOPHNrnQxvt9lSSBq2HB6vkY8LXvfUpTt6sqz2xRhvyh0LHyd KQ0Fk6DBraxMu47BhK63vx9qTLHdfm/zz0BFb+lf3H6Moul1gxSLpIPa1ZTNmbSsfT4n Ixjw== X-Gm-Message-State: AJIora+JpFsGQuOIE/pxm95lmpV+HPwbBvSwIOHusqlyQ6nKEqphb1Dl ZRFNVDa11gkDi4pZJl9NNXzIqg== X-Received: by 2002:a17:903:110d:b0:168:c610:9a80 with SMTP id n13-20020a170903110d00b00168c6109a80mr40966937plh.12.1656021162711; Thu, 23 Jun 2022 14:52:42 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id h4-20020a17090adb8400b001ecb28cfbfesm199878pjv.51.2022.06.23.14.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 14:52:42 -0700 (PDT) Date: Thu, 23 Jun 2022 21:52:38 +0000 From: Sean Christopherson To: Peter Xu Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Andrew Morton , David Hildenbrand , "Dr . David Alan Gilbert" , Andrea Arcangeli , Linux MM Mailing List Subject: Re: [PATCH 2/4] kvm: Merge "atomic" and "write" in __gfn_to_pfn_memslot() Message-ID: References: <20220622213656.81546-1-peterx@redhat.com> <20220622213656.81546-3-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 23, 2022, Peter Xu wrote: > On Thu, Jun 23, 2022 at 08:29:13PM +0000, Sean Christopherson wrote: > > This is what I came up with for splitting @async into a pure input (no_wait) and > > a return value (KVM_PFN_ERR_NEEDS_IO). > > The attached patch looks good to me. It's just that.. > > [...] > > > kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, > > - bool atomic, bool *async, bool write_fault, > > + bool atomic, bool no_wait, bool write_fault, > > bool *writable, hva_t *hva) > > .. with this patch on top we'll have 3 booleans already. With the new one > to add separated as suggested then it'll hit 4. > > Let's say one day we'll have that struct, but.. are you sure you think > keeping four booleans around is nicer than having a flag, no matter whether > we'd like to have a struct or not? No. > kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, > bool atomic, bool no_wait, bool write_fault, > bool interruptible, bool *writable, hva_t *hva); > > What if the booleans goes to 5, 6, or more? > > /me starts to wonder what'll be the magic number that we'll start to think > a bitmask flag will be more lovely here. :) For the number to really matter, it'd have to be comically large, e.g. 100+. This is all on-stack memory, so it's as close to free as can we can get. Overhead in terms of (un)marshalling is likely a wash for flags versus bools. Bools pack in nicely, so until there are a _lot_ of bools, memory is a non-issue. That leaves readability, which isn't dependent on the number so much as it is on the usage, and will be highly subjective based on the final code. In other words, I'm not dead set against flags, but I would like to see a complete cleanup before making a decision. My gut reaction is to use bools, as it makes consumption cleaner in most cases, e.g. if (!(xxx->write_fault || writable)) return false; versus if (!((xxx->flags & KVM_GTP_WRITE) || writable)) return false; but again I'm not going to say never until I actually see the end result.